jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_16nw.c
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2003 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * FUNCTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *   Internal functions for mlib_ImageConv* on U8/S16/U16 types and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *   MLIB_EDGE_DST_NO_WRITE mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "mlib_image.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "mlib_c_ImageConv.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  This define switches between functions of different data types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#define IMG_TYPE 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#if IMG_TYPE == 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#define DTYPE             mlib_u8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#define CONV_FUNC(KERN)   mlib_c_conv##KERN##nw_u8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#define CONV_FUNC_I(KERN) mlib_i_conv##KERN##nw_u8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#define DSCALE            (1 << 24)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#define FROM_S32(x)       (((x) >> 24) ^ 128)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#define S64TOS32(x)       (x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#define SAT_OFF           -(1u << 31)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#elif IMG_TYPE == 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#define DTYPE             mlib_s16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#define CONV_FUNC(KERN)   mlib_conv##KERN##nw_s16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#define CONV_FUNC_I(KERN) mlib_i_conv##KERN##nw_s16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#define DSCALE            65536.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#define FROM_S32(x)       ((x) >> 16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#define S64TOS32(x)       ((x) & 0xffffffff)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#define SAT_OFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#elif IMG_TYPE == 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#define DTYPE             mlib_u16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#define CONV_FUNC(KERN)   mlib_conv##KERN##nw_u16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define CONV_FUNC_I(KERN) mlib_i_conv##KERN##nw_u16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#define DSCALE            65536.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#define FROM_S32(x)       (((x) >> 16) ^ 0x8000)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#define S64TOS32(x)       (x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#define SAT_OFF           -(1u << 31)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#endif /* IMG_TYPE == 1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
#define BUFF_SIZE   1600
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
#define CACHE_SIZE  (64*1024)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#define FTYPE mlib_d64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#ifndef MLIB_USE_FTOI_CLAMPING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#define CLAMP_S32(x)                                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  (((x) <= MLIB_S32_MIN) ? MLIB_S32_MIN : (((x) >= MLIB_S32_MAX) ? MLIB_S32_MAX : (mlib_s32)(x)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#define CLAMP_S32(x) ((mlib_s32)(x))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
#endif /* MLIB_USE_FTOI_CLAMPING */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
#define D2I(x) CLAMP_S32((x) SAT_OFF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
#ifdef _LITTLE_ENDIAN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
#define STORE2(res0, res1)                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  dp[0    ] = res1;                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  dp[chan1] = res0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#define STORE2(res0, res1)                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  dp[0    ] = res0;                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  dp[chan1] = res1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
#endif /* _LITTLE_ENDIAN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
#define LOAD_BUFF(buff)                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  buff[i    ] = sp[0];                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
  buff[i + 1] = sp[chan1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#ifdef _LITTLE_ENDIAN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
#define LOAD_BUFF(buff)                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  *(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) | S64TOS32((mlib_s64)sp[0])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
#else /* _LITTLE_ENDIAN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
#define LOAD_BUFF(buff)                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  *(mlib_s64*)(buff + i) = (((mlib_s64)sp[0]) << 32) | S64TOS32((mlib_s64)sp[chan1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
#endif /* _LITTLE_ENDIAN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
typedef union {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  mlib_d64 d64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    mlib_s32 i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    mlib_s32 i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
  } i32s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
  struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    mlib_s32 f0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    mlib_s32 f1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
  } f32s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
} d64_2x32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
#define BUFF_LINE 256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
#define DEF_VARS(type)                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  type     *adr_src, *sl, *sp;                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  type     *adr_dst, *dl, *dp;                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
  FTYPE    *pbuff = buff;                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
  mlib_s32 wid, hgt, sll, dll;                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
  mlib_s32 nchannel, chan1;                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  mlib_s32 i, j, c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
#define LOAD_KERNEL3()                                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  FTYPE    scalef = DSCALE;                                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  FTYPE    k0, k1, k2, k3, k4, k5, k6, k7, k8;                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  FTYPE    p00, p01, p02, p03,                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
           p10, p11, p12, p13,                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
           p20, p21, p22, p23;                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
  while (scalef_expon > 30) {                                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    scalef /= (1 << 30);                                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    scalef_expon -= 30;                                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
  }                                                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
  scalef /= (1 << scalef_expon);                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  /* keep kernel in regs */                                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
  k0 = scalef * kern[0];  k1 = scalef * kern[1];  k2 = scalef * kern[2]; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
  k3 = scalef * kern[3];  k4 = scalef * kern[4];  k5 = scalef * kern[5]; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
  k6 = scalef * kern[6];  k7 = scalef * kern[7];  k8 = scalef * kern[8]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
#define LOAD_KERNEL(SIZE)                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
  FTYPE    scalef = DSCALE;                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                                                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
  while (scalef_expon > 30) {                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    scalef /= (1 << 30);                                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    scalef_expon -= 30;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
  }                                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                                                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
  scalef /= (1 << scalef_expon);                                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                                                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  for (j = 0; j < SIZE; j++) k[j] = scalef * kern[j]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
#define GET_SRC_DST_PARAMETERS(type)                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
  hgt = mlib_ImageGetHeight(src);                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  wid = mlib_ImageGetWidth(src);                                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
  nchannel = mlib_ImageGetChannels(src);                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
  sll = mlib_ImageGetStride(src) / sizeof(type);                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
  dll = mlib_ImageGetStride(dst) / sizeof(type);                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  adr_src = (type *)mlib_ImageGetData(src);                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
  adr_dst = (type *)mlib_ImageGetData(dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
#ifndef __sparc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
#if IMG_TYPE == 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
/* Test for the presence of any "1" bit in bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
   8 to 31 of val. If present, then val is either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
   negative or >255. If over/underflows of 8 bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
   are uncommon, then this technique can be a win,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
   since only a single test, rather than two, is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
   necessary to determine if clamping is needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
   On the other hand, if over/underflows are common,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
   it adds an extra test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
#define CLAMP_STORE(dst, val)                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  if (val & 0xffffff00) {                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    if (val < MLIB_U8_MIN)                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      dst = MLIB_U8_MIN;                                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    else                                                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
      dst = MLIB_U8_MAX;                                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
  } else {                                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    dst = (mlib_u8)val;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
#elif IMG_TYPE == 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
#define CLAMP_STORE(dst, val)                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
  if (val >= MLIB_S16_MAX)                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    dst = MLIB_S16_MAX;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
  else if (val <= MLIB_S16_MIN)                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    dst = MLIB_S16_MIN;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  else                                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    dst = (mlib_s16)val
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
#elif IMG_TYPE == 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
#define CLAMP_STORE(dst, val)                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
  if (val >= MLIB_U16_MAX)                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    dst = MLIB_U16_MAX;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  else if (val <= MLIB_U16_MIN)                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    dst = MLIB_U16_MIN;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  else                                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    dst = (mlib_u16)val
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
#endif /* IMG_TYPE == 1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
#endif /* __sparc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
#define KSIZE  3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
mlib_status CONV_FUNC(3x3)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                           const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                           mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
  FTYPE    buff[(KSIZE + 2)*BUFF_LINE], *buff0, *buff1, *buff2, *buff3, *buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
  DTYPE *sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
  mlib_s32 chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
  mlib_s32 *buffo, *buffi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
  DTYPE *sl2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
#ifndef __sparc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
  mlib_s32 d0, d1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
#endif /* __sparc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
  LOAD_KERNEL3();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
  if (wid > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    pbuff = mlib_malloc((KSIZE + 2)*sizeof(FTYPE)*wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
  buff0 = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
  buff1 = buff0 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
  buff2 = buff1 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
  buff3 = buff2 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
  buffo = (mlib_s32*)(buff3 + wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
  buffi = buffo + (wid &~ 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    sl1 = sl  + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    sl2 = sl1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    for (i = 0; i < wid + (KSIZE - 1); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
      buff0[i] = (FTYPE)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
      buff1[i] = (FTYPE)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
      buff2[i] = (FTYPE)sl2[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    sl += KSIZE*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
      FTYPE    s0, s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
      p02 = buff0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
      p12 = buff1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
      p22 = buff2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
      p03 = buff0[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
      p13 = buff1[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      p23 = buff2[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
      s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      s1 = p03 * k0 + p13 * k3 + p23 * k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
#ifdef __sparc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        mlib_s32 o64_1, o64_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        mlib_s64 o64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
#endif /* __sparc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        d64_2x32 dd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        LOAD_BUFF(buffi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        dd.d64 = *(FTYPE   *)(buffi + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        buff3[i    ] = (FTYPE)dd.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        buff3[i + 1] = (FTYPE)dd.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
#ifndef __sparc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        d0 = D2I(s0 + p02 * k2 + p12 * k5 + p22 * k8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        d1 = D2I(s1 + p02 * k1 + p03 * k2 + p12 * k4 + p13 * k5 + p22 * k7 + p23 * k8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        s1 = p03 * k0 + p13 * k3 + p23 * k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        dp[0    ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        dp[chan1] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
#else /* __sparc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        dd.i32s.i0 = D2I(s0 + p02 * k2 + p12 * k5 + p22 * k8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        dd.i32s.i1 = D2I(s1 + p02 * k1 + p03 * k2 + p12 * k4 + p13 * k5 + p22 * k7 + p23 * k8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        *(FTYPE   *)(buffo + i) = dd.d64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        s1 = p03 * k0 + p13 * k3 + p23 * k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        o64_1 = buffo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        o64_2 = buffo[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
#if IMG_TYPE != 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        STORE2(FROM_S32(o64_1), FROM_S32(o64_2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        STORE2(o64_1 >> 24, o64_2 >> 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
#endif /* IMG_TYPE != 1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        o64 = *(mlib_s64*)(buffo + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
#if IMG_TYPE != 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        STORE2(FROM_S32(o64 >> 32), FROM_S32(o64));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        STORE2(o64 >> 56, o64 >> 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
#endif /* IMG_TYPE != 1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
#endif /* __sparc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        buffi[i] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        buff3[i] = (FTYPE)buffi[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
#ifndef __sparc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        d0 = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p10 * k3 + p11 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                 p12 * k5 + p20 * k6 + p21 * k7 + p22 * k8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        dp[0] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
#else  /* __sparc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        buffo[i] = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p10 * k3 + p11 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                       p12 * k5 + p20 * k6 + p21 * k7 + p22 * k8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
#if IMG_TYPE != 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        dp[0] = FROM_S32(buffo[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        dp[0] = buffo[i] >> 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
#endif /* IMG_TYPE != 1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
#endif /* __sparc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
      buffi[wid] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
      buff3[wid] = (FTYPE)buffi[wid];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
      buffi[wid + 1] = (mlib_s32)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
      buff3[wid + 1] = (FTYPE)buffi[wid + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
      buff2 = buff3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
      buff3 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
#ifdef __sparc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
#if IMG_TYPE == 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    mlib_s32 amask = (1 << nchannel) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    if ((cmask & amask) != amask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
      mlib_ImageXor80(adr_dst, wid, hgt, dll, nchannel, cmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      mlib_ImageXor80_aa(adr_dst, wid*nchannel, hgt, dll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
#endif /* IMG_TYPE == 1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
#endif /* __sparc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
#ifndef __sparc /* for x86, using integer multiplies is faster */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
mlib_status CONV_FUNC_I(3x3)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                             const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                             const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                             mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                             mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
  DTYPE    *adr_src, *sl, *sp0, *sp1, *sp2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
  DTYPE    *adr_dst, *dl, *dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
  mlib_s32 wid, hgt, sll, dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
  mlib_s32 nchannel, chan1, chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
  mlib_s32 i, j, c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
  mlib_s32 shift1, shift2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
  mlib_s32 k0, k1, k2, k3, k4, k5, k6, k7, k8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
  mlib_s32 p02, p03,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
           p12, p13,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
           p22, p23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
#if IMG_TYPE != 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
  shift1 = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
  shift1 = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
#endif /* IMG_TYPE != 1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
  shift2 = scalef_expon - shift1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
  /* keep kernel in regs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
  k0 = kern[0] >> shift1;  k1 = kern[1] >> shift1;  k2 = kern[2] >> shift1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
  k3 = kern[3] >> shift1;  k4 = kern[4] >> shift1;  k5 = kern[5] >> shift1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
  k6 = kern[6] >> shift1;  k7 = kern[7] >> shift1;  k8 = kern[8] >> shift1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
      mlib_s32 s0, s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
      mlib_s32 pix0, pix1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
      dp  = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
      sp0 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
      sp1 = sp0 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
      sp2 = sp1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
      p02 = sp0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
      p12 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
      p22 = sp2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
      p03 = sp0[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
      p13 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
      p23 = sp2[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
      s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
      s1 = p03 * k0 + p13 * k3 + p23 * k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
      sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
      sp1 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
      sp2 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        p02 = sp0[0];     p12 = sp1[0];     p22 = sp2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        p03 = sp0[chan1]; p13 = sp1[chan1]; p23 = sp2[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        pix0 = (s0 + p02 * k2 + p12 * k5 + p22 * k8) >> shift2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        pix1 = (s1 + p02 * k1 + p03 * k2 + p12 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                p13 * k5 + p22 * k7 + p23 * k8) >> shift2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        CLAMP_STORE(dp[0],     pix0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        CLAMP_STORE(dp[chan1], pix1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        s1 = p03 * k0 + p13 * k3 + p23 * k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        sp1 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        sp2 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        p02 = sp0[0]; p12 = sp1[0]; p22 = sp2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        pix0 = (s0 + p02 * k2 + p12 * k5 + p22 * k8) >> shift2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        CLAMP_STORE(dp[0], pix0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
#endif /* __sparc ( for x86, using integer multiplies is faster ) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
#define KSIZE 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
mlib_status CONV_FUNC(4x4)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                           const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                           mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
  FTYPE    buff[(KSIZE + 3)*BUFF_LINE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
  FTYPE    *buff0, *buff1, *buff2, *buff3, *buff4, *buffd, *buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
  FTYPE    k[KSIZE*KSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
  mlib_s32 d0, d1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
  FTYPE    k0, k1, k2, k3, k4, k5, k6, k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
  FTYPE    p00, p01, p02, p03, p04,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
           p10, p11, p12, p13, p14,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
           p20, p21, p22, p23,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
           p30, p31, p32, p33;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
  DTYPE *sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
  mlib_s32 chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
  mlib_s32 *buffo, *buffi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
  DTYPE *sl2, *sl3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
  LOAD_KERNEL(KSIZE*KSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
  if (wid > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    pbuff = mlib_malloc((KSIZE + 3)*sizeof(FTYPE)*wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
  buff0 = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
  buff1 = buff0 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
  buff2 = buff1 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
  buff3 = buff2 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
  buff4 = buff3 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
  buffd = buff4 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
  buffo = (mlib_s32*)(buffd + wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
  buffi = buffo + (wid &~ 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    sl1 = sl  + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    sl2 = sl1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    sl3 = sl2 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    for (i = 0; i < wid + (KSIZE - 1); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
      buff0[i] = (FTYPE)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
      buff1[i] = (FTYPE)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
      buff2[i] = (FTYPE)sl2[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
      buff3[i] = (FTYPE)sl3[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    sl += KSIZE*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
      d64_2x32 dd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
       *  First loop on two first lines of kernel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
      k0 = k[0]; k1 = k[1]; k2 = k[2]; k3 = k[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
      k4 = k[4]; k5 = k[5]; k6 = k[6]; k7 = k[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
      p02 = buff0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
      p12 = buff1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
      p03 = buff0[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
      p13 = buff1[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
      p04 = buff0[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        p02 = p04; p12 = buff1[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        p03 = buff0[i + 3]; p13 = buff1[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        p04 = buff0[i + 4]; p14 = buff1[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        LOAD_BUFF(buffi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        dd.d64 = *(FTYPE   *)(buffi + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        buff4[i    ] = (FTYPE)dd.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        buff4[i + 1] = (FTYPE)dd.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        buffd[i    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                        p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        buffd[i + 1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                        p11 * k4 + p12 * k5 + p13 * k6 + p14 * k7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
       *  Second loop on two last lines of kernel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
      k0 = k[ 8]; k1 = k[ 9]; k2 = k[10]; k3 = k[11];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
      k4 = k[12]; k5 = k[13]; k6 = k[14]; k7 = k[15];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
      p02 = buff2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
      p12 = buff3[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
      p03 = buff2[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
      p13 = buff3[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
      p04 = buff2[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        p02 = p04; p12 = buff3[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        p03 = buff2[i + 3]; p13 = buff3[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        p04 = buff2[i + 4]; p14 = buff3[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        d0 = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                 p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7 + buffd[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        d1 = D2I(p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                 p11 * k4 + p12 * k5 + p13 * k6 + p14 * k7 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        dp[0    ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        dp[chan1] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
      /* last pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];     p30 = buff3[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1]; p31 = buff3[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2]; p32 = buff3[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3]; p33 = buff3[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        buff4[i] = (FTYPE)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        buffo[i] = D2I(p00 * k[0] + p01 * k[1] + p02 * k[2] + p03 * k[3] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                       p10 * k[4] + p11 * k[5] + p12 * k[6] + p13 * k[7] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                       p20 * k[ 8] + p21 * k[ 9] + p22 * k[10] + p23 * k[11] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                       p30 * k[12] + p31 * k[13] + p32 * k[14] + p33 * k[15]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        dp[0] = FROM_S32(buffo[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
      buff4[wid    ] = (FTYPE)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
      buff4[wid + 1] = (FTYPE)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
      buff4[wid + 2] = (FTYPE)sp[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
      buff2 = buff3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
      buff3 = buff4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
      buff4 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
#define KSIZE 5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
mlib_status CONV_FUNC(5x5)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                           const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                           mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
  FTYPE    buff[(KSIZE + 3)*BUFF_LINE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
  FTYPE    *buff0, *buff1, *buff2, *buff3, *buff4, *buff5, *buffd, *buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
  FTYPE    k[KSIZE*KSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
  mlib_s32 d0, d1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
  FTYPE    k0, k1, k2, k3, k4, k5, k6, k7, k8, k9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
  FTYPE    p00, p01, p02, p03, p04, p05,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
           p10, p11, p12, p13, p14, p15,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
           p20, p21, p22, p23, p24,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
           p30, p31, p32, p33, p34,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
           p40, p41, p42, p43, p44;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
  DTYPE *sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
  mlib_s32 chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
  mlib_s32 *buffo, *buffi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
  DTYPE *sl2, *sl3, *sl4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
  LOAD_KERNEL(KSIZE*KSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
  if (wid > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    pbuff = mlib_malloc((KSIZE + 3)*sizeof(FTYPE)*wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
  buff0 = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
  buff1 = buff0 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
  buff2 = buff1 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
  buff3 = buff2 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
  buff4 = buff3 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
  buff5 = buff4 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
  buffd = buff5 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
  buffo = (mlib_s32*)(buffd + wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
  buffi = buffo + (wid &~ 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    sl1 = sl  + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    sl2 = sl1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    sl3 = sl2 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    sl4 = sl3 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    for (i = 0; i < wid + (KSIZE - 1); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
      buff0[i] = (FTYPE)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
      buff1[i] = (FTYPE)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
      buff2[i] = (FTYPE)sl2[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
      buff3[i] = (FTYPE)sl3[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
      buff4[i] = (FTYPE)sl4[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    sl += KSIZE*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
      d64_2x32 dd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
       *  First loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
      k0 = k[0]; k1 = k[1]; k2 = k[2]; k3 = k[3]; k4 = k[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
      k5 = k[5]; k6 = k[6]; k7 = k[7]; k8 = k[8]; k9 = k[9];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
      p02 = buff0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
      p12 = buff1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
      p03 = buff0[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
      p13 = buff1[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
      p04 = buff0[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
      p14 = buff1[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        LOAD_BUFF(buffi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        p03 = buff0[i + 3]; p13 = buff1[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        p04 = buff0[i + 4]; p14 = buff1[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        p05 = buff0[i + 5]; p15 = buff1[i + 5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        buffd[i    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                        p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        buffd[i + 1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                        p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
       *  Second loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
      k0 = k[10]; k1 = k[11]; k2 = k[12]; k3 = k[13]; k4 = k[14];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
      k5 = k[15]; k6 = k[16]; k7 = k[17]; k8 = k[18]; k9 = k[19];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
      p02 = buff2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
      p12 = buff3[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
      p03 = buff2[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
      p13 = buff3[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
      p04 = buff2[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
      p14 = buff3[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        p02 = buff2[i + 2]; p12 = buff3[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        p03 = buff2[i + 3]; p13 = buff3[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        p04 = buff2[i + 4]; p14 = buff3[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        p05 = buff2[i + 5]; p15 = buff3[i + 5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        dd.d64 = *(FTYPE   *)(buffi + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        buff5[i    ] = (FTYPE)dd.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        buff5[i + 1] = (FTYPE)dd.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        buffd[i    ] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                         p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        buffd[i + 1] += (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                         p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
       *  3 loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
      k0 = k[20]; k1 = k[21]; k2 = k[22]; k3 = k[23]; k4 = k[24];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
      p02 = buff4[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
      p03 = buff4[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
      p04 = buff4[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
      p05 = buff4[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        p00 = p02; p01 = p03; p02 = p04; p03 = p05;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        p04 = buff4[i + 4]; p05 = buff4[i + 5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        d0 = D2I(p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 + buffd[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        d1 = D2I(p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        dp[0    ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        dp[chan1] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
      /* last pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];     p30 = buff3[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1]; p31 = buff3[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2]; p32 = buff3[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3]; p33 = buff3[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        p04 = buff0[i + 4]; p14 = buff1[i + 4]; p24 = buff2[i + 4]; p34 = buff3[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        p40 = buff4[i];     p41 = buff4[i + 1]; p42 = buff4[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        p43 = buff4[i + 3]; p44 = buff4[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        buff5[i] = (FTYPE)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        buffo[i] = D2I(p00 * k[0] + p01 * k[1] + p02 * k[2] + p03 * k[3] + p04 * k[4] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                       p10 * k[5] + p11 * k[6] + p12 * k[7] + p13 * k[8] + p14 * k[9] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                       p20 * k[10] + p21 * k[11] + p22 * k[12] + p23 * k[13] + p24 * k[14] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                       p30 * k[15] + p31 * k[16] + p32 * k[17] + p33 * k[18] + p34 * k[19] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                       p40 * k[20] + p41 * k[21] + p42 * k[22] + p43 * k[23] + p44 * k[24]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        dp[0] = FROM_S32(buffo[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
      buff5[wid    ] = (FTYPE)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
      buff5[wid + 1] = (FTYPE)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
      buff5[wid + 2] = (FTYPE)sp[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
      buff5[wid + 3] = (FTYPE)sp[chan2 + chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
      buff2 = buff3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
      buff3 = buff4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
      buff4 = buff5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
      buff5 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
#ifndef __sparc /* for x86, using integer multiplies is faster */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
mlib_status CONV_FUNC_I(5x5)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                             const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                             const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                             mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                             mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
  mlib_s32 buff[BUFF_LINE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
  mlib_s32 *buffd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
  mlib_s32 k[KSIZE*KSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
  mlib_s32 shift1, shift2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
  mlib_s32 k0, k1, k2, k3, k4, k5, k6, k7, k8, k9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
  mlib_s32 p00, p01, p02, p03, p04, p05,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
           p10, p11, p12, p13, p14, p15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
  DTYPE    *adr_src, *sl, *sp0, *sp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
  DTYPE    *adr_dst, *dl, *dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
  mlib_s32 *pbuff = buff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
  mlib_s32 wid, hgt, sll, dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
  mlib_s32 nchannel, chan1, chan2, chan3, chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
  mlib_s32 i, j, c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
#if IMG_TYPE != 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
  shift1 = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
  shift1 = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
#endif /* IMG_TYPE != 1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
  shift2 = scalef_expon - shift1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
  for (j = 0; j < KSIZE*KSIZE; j++) k[j] = kern[j] >> shift1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
  if (wid > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    pbuff = mlib_malloc(sizeof(mlib_s32)*wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
  buffd = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
  chan3 = chan2 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
  chan4 = chan3 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
      mlib_s32 pix0, pix1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
       *  First loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
      sp0 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
      sp1 = sp0 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
      k0 = k[0]; k1 = k[1]; k2 = k[2]; k3 = k[3]; k4 = k[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
      k5 = k[5]; k6 = k[6]; k7 = k[7]; k8 = k[8]; k9 = k[9];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
      p02 = sp0[0];     p12 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
      p03 = sp0[chan1]; p13 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
      p04 = sp0[chan2]; p14 = sp1[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
      p05 = sp0[chan3]; p15 = sp1[chan3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
      sp0 += chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
      sp1 += chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        p03 = p05; p13 = p15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        p04 = sp0[0];     p14 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        p05 = sp0[chan1]; p15 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        buffd[i    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                        p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        buffd[i + 1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                        p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        sp1 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        p03 = p05; p13 = p15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        p04 = sp0[0];     p14 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        buffd[i] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                    p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
       *  Second loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
      sp0 = sl + 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
      sp1 = sp0 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
      k0 = k[10]; k1 = k[11]; k2 = k[12]; k3 = k[13]; k4 = k[14];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
      k5 = k[15]; k6 = k[16]; k7 = k[17]; k8 = k[18]; k9 = k[19];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
      p02 = sp0[0];     p12 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
      p03 = sp0[chan1]; p13 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
      p04 = sp0[chan2]; p14 = sp1[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
      p05 = sp0[chan3]; p15 = sp1[chan3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
      sp0 += chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
      sp1 += chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        p03 = p05; p13 = p15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        p04 = sp0[0];     p14 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        p05 = sp0[chan1]; p15 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        buffd[i    ] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                         p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        buffd[i + 1] += (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                         p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        sp1 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        p03 = p05; p13 = p15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        p04 = sp0[0];     p14 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        buffd[i] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                     p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
       *  3 loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
      sp0 = sl + 4*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
      k0 = k[20]; k1 = k[21]; k2 = k[22]; k3 = k[23]; k4 = k[24];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
      p02 = sp0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
      p03 = sp0[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
      p04 = sp0[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
      p05 = sp0[chan3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
      sp0 += chan2 + chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        p00 = p02; p01 = p03; p02 = p04; p03 = p05;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        p04 = sp0[0]; p05 = sp0[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        pix0 = (buffd[i    ] + p00 * k0 + p01 * k1 + p02 * k2 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                p03 * k3 + p04 * k4) >> shift2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        pix1 = (buffd[i + 1] + p01 * k0 + p02 * k1 + p03 * k2 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                p04 * k3 + p05 * k4) >> shift2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        CLAMP_STORE(dp[0],     pix0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        CLAMP_STORE(dp[chan1], pix1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        dp  += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        p00 = p02; p01 = p03; p02 = p04; p03 = p05;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        p04 = sp0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        pix0 = (buffd[i    ] + p00 * k0 + p01 * k1 + p02 * k2 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                p03 * k3 + p04 * k4) >> shift2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        CLAMP_STORE(dp[0],     pix0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
#endif /* __sparc ( for x86, using integer multiplies is faster ) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
#if IMG_TYPE == 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
#define KSIZE 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
mlib_status CONV_FUNC(7x7)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                           const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                           mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
  FTYPE    buff[(KSIZE + 3)*BUFF_LINE], *buffs[2*(KSIZE + 1)], *buffd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
  FTYPE    k[KSIZE*KSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
  mlib_s32 l, m, buff_ind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
  mlib_s32 d0, d1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
  FTYPE    k0, k1, k2, k3, k4, k5, k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
  FTYPE    p0, p1, p2, p3, p4, p5, p6, p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
  DTYPE *sl2, *sl3, *sl4, *sl5, *sl6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
  DTYPE *sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
  mlib_s32 chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
  mlib_s32 *buffo, *buffi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
  LOAD_KERNEL(KSIZE*KSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
  if (wid > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    pbuff = mlib_malloc((KSIZE + 3)*sizeof(FTYPE)*wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
  for (l = 0; l < KSIZE + 1; l++) buffs[l] = pbuff + l*wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
  for (l = 0; l < KSIZE + 1; l++) buffs[l + (KSIZE + 1)] = buffs[l];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
  buffd = buffs[KSIZE] + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
  buffo = (mlib_s32*)(buffd + wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
  buffi = buffo + (wid &~ 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    sl1 = sl  + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    sl2 = sl1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    sl3 = sl2 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    sl4 = sl3 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    sl5 = sl4 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    sl6 = sl5 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    for (i = 0; i < wid + (KSIZE - 1); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
      buffs[0][i] = (FTYPE)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
      buffs[1][i] = (FTYPE)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
      buffs[2][i] = (FTYPE)sl2[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
      buffs[3][i] = (FTYPE)sl3[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
      buffs[4][i] = (FTYPE)sl4[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
      buffs[5][i] = (FTYPE)sl5[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
      buffs[6][i] = (FTYPE)sl6[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    buff_ind = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    for (i = 0; i < wid; i++) buffd[i] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    sl += KSIZE*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
      FTYPE    **buffc = buffs + buff_ind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
      FTYPE    *buffn = buffc[KSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
      FTYPE    *pk = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
      for (l = 0; l < KSIZE; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        FTYPE    *buff = buffc[l];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        d64_2x32 dd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        p5 = buff[3]; p6 = buff[4]; p7 = buff[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        k0 = *pk++; k1 = *pk++; k2 = *pk++; k3 = *pk++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        k4 = *pk++; k5 = *pk++; k6 = *pk++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        if (l < (KSIZE - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
          for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            p6 = buff[i + 6]; p7 = buff[i + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
          for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            p6 = buff[i + 6]; p7 = buff[i + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            LOAD_BUFF(buffi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            dd.d64 = *(FTYPE   *)(buffi + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            buffn[i    ] = (FTYPE)dd.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            buffn[i + 1] = (FTYPE)dd.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            dp[0    ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            dp[chan1] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
            buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
      /* last pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        FTYPE    *pk = k, s = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        mlib_s32 d0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        for (l = 0; l < KSIZE; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
          FTYPE    *buff = buffc[l] + i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
          for (m = 0; m < KSIZE; m++) s += buff[m] * (*pk++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        d0 = D2I(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        dp[0] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        buffn[i] = (FTYPE)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
      for (l = 0; l < (KSIZE - 1); l++) buffn[wid + l] = sp[l*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
      buff_ind++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
      if (buff_ind >= KSIZE + 1) buff_ind = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
#endif /* IMG_TYPE == 1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
#define MAX_KER   7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
#define MAX_N    15
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
static mlib_status mlib_ImageConv1xN(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                                     const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                                     const mlib_d64   *k,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                                     mlib_s32         n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                                     mlib_s32         dn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                                     mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
  FTYPE    buff[BUFF_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
  mlib_s32 off, kh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
  mlib_s32 d0, d1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
  const FTYPE    *pk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
  FTYPE    k0, k1, k2, k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
  FTYPE    p0, p1, p2, p3, p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
  DTYPE    *sl_c, *dl_c, *sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
  mlib_s32 l, hsize, max_hsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
  hgt -= (n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
  adr_dst += dn*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
  max_hsize = (CACHE_SIZE/sizeof(DTYPE))/sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
  if (!max_hsize) max_hsize = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
  if (max_hsize > BUFF_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
    pbuff = mlib_malloc(sizeof(FTYPE)*max_hsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
  sl_c = adr_src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
  dl_c = adr_dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
  for (l = 0; l < hgt; l += hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
    hsize = hgt - l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    if (hsize > max_hsize) hsize = max_hsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
    for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
      if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
      sl = sl_c + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
      dl = dl_c + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
      for (j = 0; j < hsize; j++) pbuff[j] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
      for (i = 0; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        sl0 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        for (off = 0; off < (n - 4); off += 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
          pk = k + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
          sp = sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
          k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
          p2 = sp[0]; p3 = sp[sll]; p4 = sp[2*sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
          sp += 3*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
          for (j = 0; j < hsize; j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            p4 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
            pbuff[j    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            pbuff[j + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
          sl0 += 4*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        pk = k + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        sp = sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        p2 = sp[0]; p3 = sp[sll]; p4 = sp[2*sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        kh = n - off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        if (kh == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
          sp += 3*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            p4 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + pbuff[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + pbuff[j + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            dp[0  ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            dp[dll] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + pbuff[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
            dp[0] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        } else if (kh == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
          sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
            p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            p2 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
            p3 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
            d0 = D2I(p0*k0 + p1*k1 + p2*k2 + pbuff[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            d1 = D2I(p1*k0 + p2*k1 + p3*k2 + pbuff[j + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
            dp[0  ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            dp[dll] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
            p2 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
            d0 = D2I(p0*k0 + p1*k1 + p2*k2 + pbuff[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            dp[0] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        } else if (kh == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
          sp += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
            p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            p1 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            p2 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            d0 = D2I(p0*k0 + p1*k1 + pbuff[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            d1 = D2I(p1*k0 + p2*k1 + pbuff[j + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            dp[0  ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            dp[dll] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
            p1 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
            d0 = D2I(p0*k0 + p1*k1 + pbuff[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
            dp[0] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
        } else /* if (kh == 1) */ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
          for (j = 0; j < hsize; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
            p0 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            d0 = D2I(p0*k0 + pbuff[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
            dp[0] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            sp += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
            dp += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        sl += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        dl += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    sl_c += max_hsize*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
    dl_c += max_hsize*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
mlib_status CONV_FUNC(MxN)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                           const mlib_s32   *kernel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                           mlib_s32         m,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                           mlib_s32         n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                           mlib_s32         dm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                           mlib_s32         dn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                           mlib_s32         scale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
  FTYPE    buff[BUFF_SIZE], *buffs_arr[2*(MAX_N + 1)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
  FTYPE    **buffs = buffs_arr, *buffd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
  FTYPE    akernel[256], *k = akernel, fscale = DSCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
  mlib_s32 mn, l, off, kw, bsize, buff_ind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
  mlib_s32 d0, d1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
  FTYPE    k0, k1, k2, k3, k4, k5, k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
  FTYPE    p0, p1, p2, p3, p4, p5, p6, p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
  d64_2x32 dd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
  mlib_s32 chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
  mlib_s32 *buffo, *buffi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
  if (scale > 30) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    fscale *= 1.0/(1 << 30);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
    scale -= 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
  fscale /= (1 << scale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
  mn = m*n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
  if (mn > 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
    k = mlib_malloc(mn*sizeof(mlib_d64));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    if (k == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
  for (i = 0; i < mn; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
    k[i] = kernel[i]*fscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
  if (m == 1) return mlib_ImageConv1xN(dst, src, k, n, dn, cmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
  bsize = (n + 3)*wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
  if ((bsize > BUFF_SIZE) || (n > MAX_N)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    pbuff = mlib_malloc(sizeof(FTYPE)*bsize + sizeof(FTYPE *)*2*(n + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
    buffs = (FTYPE   **)(pbuff + bsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
  for (l = 0; l < (n + 1); l++) buffs[l] = pbuff + l*wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
  for (l = 0; l < (n + 1); l++) buffs[l + (n + 1)] = buffs[l];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
  buffd = buffs[n] + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
  buffo = (mlib_s32*)(buffd + wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
  buffi = buffo + (wid &~ 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
  wid -= (m - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
  hgt -= (n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
  adr_dst += dn*dll + dm*nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
    for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
      FTYPE    *buff = buffs[l];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
      for (i = 0; i < wid + (m - 1); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
        buff[i] = (FTYPE)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    buff_ind = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    for (i = 0; i < wid; i++) buffd[i] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
      FTYPE    **buffc = buffs + buff_ind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
      FTYPE    *buffn = buffc[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
      FTYPE    *pk = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
      for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        FTYPE    *buff_l = buffc[l];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        for (off = 0; off < m;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
          FTYPE    *buff = buff_l + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
          kw = m - off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
          if (kw > 2*MAX_KER) kw = MAX_KER; else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            if (kw > MAX_KER) kw = kw/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
          off += kw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
          sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
          dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
          p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
          p5 = buff[3]; p6 = buff[4]; p7 = buff[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
          k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
          k4 = pk[4]; k5 = pk[5]; k6 = pk[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
          pk += kw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
          if (kw == 7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                p6 = buff[i + 6]; p7 = buff[i + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                p6 = buff[i + 6]; p7 = buff[i + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                LOAD_BUFF(buffi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                dd.d64 = *(FTYPE   *)(buffi + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                buffn[i    ] = (FTYPE)dd.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                buffn[i + 1] = (FTYPE)dd.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
                d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                dp[0    ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                dp[chan1] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
          } else if (kw == 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                p5 = buff[i + 5]; p6 = buff[i + 6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                p5 = buff[i + 5]; p6 = buff[i + 6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                buffn[i    ] = (FTYPE)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                buffn[i + 1] = (FTYPE)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                dp[0    ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                dp[chan1] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
          } else if (kw == 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                p0 = p2; p1 = p3; p2 = p4; p3 = p5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                p4 = buff[i + 4]; p5 = buff[i + 5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                p0 = p2; p1 = p3; p2 = p4; p3 = p5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                p4 = buff[i + 4]; p5 = buff[i + 5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                buffn[i    ] = (FTYPE)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                buffn[i + 1] = (FTYPE)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                dp[0    ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                dp[chan1] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
          } else if (kw == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                p3 = buff[i + 3]; p4 = buff[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
                p3 = buff[i + 3]; p4 = buff[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                buffn[i    ] = (FTYPE)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                buffn[i + 1] = (FTYPE)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                d0 = D2I(p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                d1 = D2I(p1*k0 + p2*k1 + p3*k2 + p4*k3 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                dp[0    ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                dp[chan1] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
          } else if (kw == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                p2 = buff[i + 2]; p3 = buff[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                p2 = buff[i + 2]; p3 = buff[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                buffn[i    ] = (FTYPE)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                buffn[i + 1] = (FTYPE)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                d0 = D2I(p0*k0 + p1*k1 + p2*k2 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                d1 = D2I(p1*k0 + p2*k1 + p3*k2 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                dp[0    ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                dp[chan1] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
          } else /*if (kw == 2)*/ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                p1 = buff[i + 1]; p2 = buff[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                buffd[i    ] += p0*k0 + p1*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
                buffd[i + 1] += p1*k0 + p2*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                p1 = buff[i + 1]; p2 = buff[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                buffn[i    ] = (FTYPE)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                buffn[i + 1] = (FTYPE)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                d0 = D2I(p0*k0 + p1*k1 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                d1 = D2I(p1*k0 + p2*k1 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
                dp[0    ] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                dp[chan1] = FROM_S32(d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
      /* last pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
        FTYPE    *pk = k, s = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
        mlib_s32 x, d0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
        for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
          FTYPE    *buff = buffc[l] + i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
          for (x = 0; x < m; x++) s += buff[x] * (*pk++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        d0 = D2I(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
        dp[0] = FROM_S32(d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
        buffn[i] = (FTYPE)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
      for (l = 0; l < (m - 1); l++) buffn[wid + l] = sp[l*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
      buff_ind++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
      if (buff_ind >= n + 1) buff_ind = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
#ifndef __sparc /* for x86, using integer multiplies is faster */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
#define STORE_RES(res, x)                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
  x >>= shift2;                                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
  CLAMP_STORE(res, x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
mlib_status CONV_FUNC_I(MxN)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                             const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                             const mlib_s32   *kernel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                             mlib_s32         m,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                             mlib_s32         n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                             mlib_s32         dm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                             mlib_s32         dn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                             mlib_s32         scale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
                             mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
  mlib_s32 buff[BUFF_SIZE], *buffd = buff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
  mlib_s32 l, off, kw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
  mlib_s32 d0, d1, shift1, shift2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
  mlib_s32 k0, k1, k2, k3, k4, k5, k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
  mlib_s32 p0, p1, p2, p3, p4, p5, p6, p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
  DTYPE    *adr_src, *sl, *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
  DTYPE    *adr_dst, *dl, *dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
  mlib_s32 wid, hgt, sll, dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
  mlib_s32 nchannel, chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
  mlib_s32 i, j, c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
  mlib_s32 chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
  mlib_s32 k_locl[MAX_N*MAX_N], *k = k_locl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
#if IMG_TYPE != 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
  shift1 = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
  shift1 = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
#endif /* IMG_TYPE != 1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
  shift2 = scale - shift1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
  wid -= (m - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
  hgt -= (n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
  adr_dst += dn*dll + dm*nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
  if (wid > BUFF_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
    buffd = mlib_malloc(sizeof(mlib_s32)*wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
    if (buffd == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
  if (m*n > MAX_N*MAX_N) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
    k = mlib_malloc(sizeof(mlib_s32)*(m*n));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
    if (k == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
      if (buffd != buff) mlib_free(buffd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
      return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
  for (i = 0; i < m*n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
    k[i] = kernel[i] >> shift1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
    for (i = 0; i < wid; i++) buffd[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
      mlib_s32 *pk = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
      for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        DTYPE *sp0 = sl + l*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        for (off = 0; off < m;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
          sp = sp0 + off*chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
          dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
          kw = m - off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
          if (kw > 2*MAX_KER) kw = MAX_KER; else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            if (kw > MAX_KER) kw = kw/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
          off += kw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
          p2 = sp[0]; p3 = sp[chan1]; p4 = sp[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
          p5 = sp[chan2 + chan1]; p6 = sp[chan2 + chan2]; p7 = sp[5*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
          k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
          k4 = pk[4]; k5 = pk[5]; k6 = pk[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
          pk += kw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
          sp += (kw - 1)*chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
          if (kw == 7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
                p6 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
                p7 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                p6 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
                p7 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
                d0 = (p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
                d1 = (p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
                STORE_RES(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
                STORE_RES(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
                buffd[i    ] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
                buffd[i + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
          } else if (kw == 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                p5 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
                p6 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
                p5 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                p6 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
                d0 = (p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
                d1 = (p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
                STORE_RES(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
                STORE_RES(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
                buffd[i    ] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
                buffd[i + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
          } else if (kw == 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
                p0 = p2; p1 = p3; p2 = p4; p3 = p5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
                p4 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                p5 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
                p0 = p2; p1 = p3; p2 = p4; p3 = p5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
                p4 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
                p5 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
                d0 = (p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
                d1 = (p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
                STORE_RES(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
                STORE_RES(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
                buffd[i    ] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
                buffd[i + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
          } else if (kw == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
                p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
                p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
                p4 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
                p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
                p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
                p4 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
                d0 = (p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
                d1 = (p1*k0 + p2*k1 + p3*k2 + p4*k3 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
                STORE_RES(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
                STORE_RES(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
                buffd[i    ] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
                buffd[i + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
          } else if (kw == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
                p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
                p2 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
                p3 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
                p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
                p2 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
                p3 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
                d0 = (p0*k0 + p1*k1 + p2*k2 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
                d1 = (p1*k0 + p2*k1 + p3*k2 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
                STORE_RES(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
                STORE_RES(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
                buffd[i    ] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
                buffd[i + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
          } else if (kw == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
                p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
                p1 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
                p2 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
                buffd[i    ] += p0*k0 + p1*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
                buffd[i + 1] += p1*k0 + p2*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
                p1 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
                p2 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
                d0 = (p0*k0 + p1*k1 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
                d1 = (p1*k0 + p2*k1 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
                STORE_RES(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
                STORE_RES(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
                buffd[i    ] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
                buffd[i + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
          } else /*if (kw == 1)*/ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
                p0 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
                p1 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
                buffd[i    ] += p0*k0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
                buffd[i + 1] += p1*k0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
                p0 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
                p1 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
                d0 = (p0*k0 + buffd[i    ]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
                d1 = (p1*k0 + buffd[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
                STORE_RES(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
                STORE_RES(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
                buffd[i    ] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
                buffd[i + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
      /* last pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
        mlib_s32 *pk = k, s = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
        mlib_s32 x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
        for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
          sp = sl + l*sll + i*chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
          for (x = 0; x < m; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
            s += sp[0] * pk[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
            sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
            pk ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
        STORE_RES(dp[0], s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
  if (buffd != buff) mlib_free(buffd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
  if (k != k_locl) mlib_free(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
#endif /* __sparc ( for x86, using integer multiplies is faster ) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
/***************************************************************/