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