jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_D64nw.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 D64/F32 type 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "mlib_image.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "mlib_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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  This define switches between functions of MLIB_DOUBLE and MLIB_FLOAT types:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  Files mlib_ImageConv_D64nw.c and mlib_ImageConv_F32nw.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#define TYPE_DOUBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#ifdef TYPE_DOUBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#define CONV_FUNC(KERN) mlib_conv##KERN##nw_d64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#define DTYPE mlib_d64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#define CONV_FUNC(KERN) mlib_conv##KERN##nw_f32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#define DTYPE mlib_f32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#endif /* TYPE_DOUBLE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#define GET_SRC_DST_PARAMETERS(type)                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  mlib_s32 hgt = mlib_ImageGetHeight(src);                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  mlib_s32 wid = mlib_ImageGetWidth(src);                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  mlib_s32 sll = mlib_ImageGetStride(src) / sizeof(type);       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  mlib_s32 dll = mlib_ImageGetStride(dst) / sizeof(type);       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  type*    adr_src = mlib_ImageGetData(src);                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  type*    adr_dst = mlib_ImageGetData(dst);                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  mlib_s32 chan1 = mlib_ImageGetChannels(src)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#define DEF_VARS(type)                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
  GET_SRC_DST_PARAMETERS(type);                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  type     *sl;                                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  type     *dl, *dp;                                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  mlib_s32 i, j, c
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
#define KSIZE 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
mlib_status CONV_FUNC(2x2)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                           const mlib_d64   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  DTYPE    *sp0, *sp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  mlib_s32 chan3 = chan1 + chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  mlib_s32 chan4 = chan3 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  DTYPE k0, k1, k2, k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  DTYPE p00, p01, p02, p03, p04,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        p10, p11, p12, p13, p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  /* keep kernel in regs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  k0 = (DTYPE)kern[0];  k1 = (DTYPE)kern[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  k2 = (DTYPE)kern[2];  k3 = (DTYPE)kern[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
      dp  = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
      sp0 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      sp1 = sp0 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      p04 = sp0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      p14 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
      sp0 += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      sp1 += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
      for (i = 0; i <= (wid - 4); i += 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        p00 = p04; p10 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        p01 = sp0[0];     p11 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        p02 = sp0[chan1]; p12 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        p03 = sp0[chan2]; p13 = sp1[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        p04 = sp0[chan3]; p14 = sp1[chan3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        dp[0    ] = p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        dp[chan1] = p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        dp[chan2] = p02 * k0 + p03 * k1 + p12 * k2 + p13 * k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        dp[chan3] = p03 * k0 + p04 * k1 + p13 * k2 + p14 * k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        dp  += chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        sp0 += chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        sp1 += chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      if (i < wid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        p00 = p04;    p10 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        p01 = sp0[0]; p11 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        dp[0] = p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if ((i + 1) < wid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
          p02 = sp0[chan1]; p12 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
          dp[chan1] = p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
          if ((i + 2) < wid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            p03 = sp0[chan2]; p13 = sp1[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            dp[chan2] = p02 * k0 + p03 * k1 + p12 * k2 + p13 * k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
#define KSIZE 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
mlib_status CONV_FUNC(3x3)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                           const mlib_d64   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
  DTYPE    *sp0, *sp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
  DTYPE *sp2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
  DTYPE k0, k1, k2, k3, k4, k5, k6, k7, k8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
  DTYPE p02, p03, p12, p13, p22, p23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
  /* keep kernel in regs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
  k0 = (DTYPE)kern[0];  k1 = (DTYPE)kern[1];  k2 = (DTYPE)kern[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
  k3 = (DTYPE)kern[3];  k4 = (DTYPE)kern[4];  k5 = (DTYPE)kern[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
  k6 = (DTYPE)kern[6];  k7 = (DTYPE)kern[7];  k8 = (DTYPE)kern[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
      DTYPE s0, s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
      dp  = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
      sp0 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
      sp1 = sp0 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
      sp2 = sp1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
      p02 = sp0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
      p12 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
      p22 = sp2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
      p03 = sp0[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
      p13 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
      p23 = sp2[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
      s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
      s1 = p03 * k0 + p13 * k3 + p23 * k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
      sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      sp1 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
      sp2 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        p02 = sp0[0];     p12 = sp1[0];     p22 = sp2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        p03 = sp0[chan1]; p13 = sp1[chan1]; p23 = sp2[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        dp[0    ] = s0 + p02 * k2 + p12 * k5 + p22 * k8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        dp[chan1] = s1 + p02 * k1 + p03 * k2 + p12 * k4 + p13 * k5 + p22 * k7 + p23 * k8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        s1 = p03 * k0 + p13 * k3 + p23 * k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        sp1 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        sp2 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        p02 = sp0[0]; p12 = sp1[0]; p22 = sp2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        dp[0] = s0 + p02 * k2 + p12 * k5 + p22 * k8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
#define KSIZE 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
mlib_status CONV_FUNC(4x4)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                           const mlib_d64   *k,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
  DTYPE k0, k1, k2, k3, k4, k5, k6, k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
  DTYPE p00, p01, p02, p03, p04,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        p10, p11, p12, p13, p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
  DTYPE    *sp0, *sp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
  mlib_s32 chan3 = chan1 + chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
       *  First loop on two first lines of kernel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
      sp0 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      sp1 = sp0 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
      k0 = (DTYPE)k[0]; k1 = (DTYPE)k[1]; k2 = (DTYPE)k[2]; k3 = (DTYPE)k[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
      k4 = (DTYPE)k[4]; k5 = (DTYPE)k[5]; k6 = (DTYPE)k[6]; k7 = (DTYPE)k[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      p02 = sp0[0];     p12 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
      p03 = sp0[chan1]; p13 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      p04 = sp0[chan2]; p14 = sp1[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      sp0 += chan3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
      sp1 += chan3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        p03 = sp0[0];     p13 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        p04 = sp0[chan1]; p14 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        dp[0    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                     p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        dp[chan1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                     p11 * k4 + p12 * k5 + p13 * k6 + p14 * k7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        sp1 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        p03 = sp0[0]; p13 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        dp[0] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                 p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
       *  Second loop on two last lines of kernel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
      sp0 = sl + 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
      sp1 = sp0 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
      k0 = (DTYPE)k[ 8]; k1 = (DTYPE)k[ 9]; k2 = (DTYPE)k[10]; k3 = (DTYPE)k[11];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
      k4 = (DTYPE)k[12]; k5 = (DTYPE)k[13]; k6 = (DTYPE)k[14]; k7 = (DTYPE)k[15];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
      p02 = sp0[0];     p12 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
      p03 = sp0[chan1]; p13 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
      p04 = sp0[chan2]; p14 = sp1[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
      sp0 += chan3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
      sp1 += chan3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        p03 = sp0[0];     p13 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        p04 = sp0[chan1]; p14 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        dp[0    ] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                      p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        dp[chan1] += (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                      p11 * k4 + p12 * k5 + p13 * k6 + p14 * k7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        sp1 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        p03 = sp0[0]; p13 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        dp[0] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                  p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
#define KSIZE 5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
mlib_status CONV_FUNC(5x5)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                           const mlib_d64   *k,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
  DTYPE k0, k1, k2, k3, k4, k5, k6, k7, k8, k9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
  DTYPE p00, p01, p02, p03, p04, p05,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        p10, p11, p12, p13, p14, p15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
  DTYPE    *sp0, *sp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
  mlib_s32 chan3 = chan1 + chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
  mlib_s32 chan4 = chan3 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
       *  First loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
      sp0 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
      sp1 = sp0 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
      k0 = (DTYPE)k[0]; k1 = (DTYPE)k[1]; k2 = (DTYPE)k[2]; k3 = (DTYPE)k[3]; k4 = (DTYPE)k[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
      k5 = (DTYPE)k[5]; k6 = (DTYPE)k[6]; k7 = (DTYPE)k[7]; k8 = (DTYPE)k[8]; k9 = (DTYPE)k[9];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
      p02 = sp0[0];     p12 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
      p03 = sp0[chan1]; p13 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
      p04 = sp0[chan2]; p14 = sp1[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
      p05 = sp0[chan3]; p15 = sp1[chan3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
      sp0 += chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
      sp1 += chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        p03 = p05; p13 = p15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        p04 = sp0[0];     p14 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        p05 = sp0[chan1]; p15 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        dp[    0] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                     p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        dp[chan1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                     p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        sp1 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        p03 = p05; p13 = p15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        p04 = sp0[0];     p14 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        dp[0] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                 p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
       *  Second loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
      sp0 = sl + 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
      sp1 = sp0 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
      k0 = (DTYPE)k[10]; k1 = (DTYPE)k[11]; k2 = (DTYPE)k[12]; k3 = (DTYPE)k[13]; k4 = (DTYPE)k[14];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
      k5 = (DTYPE)k[15]; k6 = (DTYPE)k[16]; k7 = (DTYPE)k[17]; k8 = (DTYPE)k[18]; k9 = (DTYPE)k[19];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
      p02 = sp0[0];     p12 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
      p03 = sp0[chan1]; p13 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
      p04 = sp0[chan2]; p14 = sp1[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
      p05 = sp0[chan3]; p15 = sp1[chan3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
      sp0 += chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
      sp1 += chan4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        p03 = p05; p13 = p15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        p04 = sp0[0];     p14 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        p05 = sp0[chan1]; p15 = sp1[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        dp[    0] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                      p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        dp[chan1] += (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                      p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        sp1 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        p03 = p05; p13 = p15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        p04 = sp0[0];     p14 = sp1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        dp[0] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                  p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
       *  3 loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
      sp0 = sl + 4*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
      k0 = (DTYPE)k[20]; k1 = (DTYPE)k[21]; k2 = (DTYPE)k[22]; k3 = (DTYPE)k[23]; k4 = (DTYPE)k[24];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
      p02 = sp0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
      p03 = sp0[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
      p04 = sp0[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
      p05 = sp0[chan3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
      sp0 += chan2 + chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        p00 = p02; p01 = p03; p02 = p04; p03 = p05;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        p04 = sp0[0]; p05 = sp0[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        dp[0    ] += p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        dp[chan1] += p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        dp  += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        p00 = p02; p01 = p03; p02 = p04; p03 = p05;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        p04 = sp0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        dp[0] += p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
#define BUFF_SIZE  1600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
#define CACHE_SIZE (64*1024)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
static mlib_status mlib_ImageConv1xN(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                     const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                                     const DTYPE      *k,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                                     mlib_s32         n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                                     mlib_s32         dn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                     mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
  DTYPE    buff[BUFF_SIZE], *pbuff = buff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
  const DTYPE    *pk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
  DTYPE    k0, k1, k2, k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
  DTYPE    p0, p1, p2, p3, p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
  DTYPE    *sp, *sl_c, *dl_c, *sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
  mlib_s32 off, kh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
  mlib_s32 l, hsize, max_hsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
  hgt -= (n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
  adr_dst += dn*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
  max_hsize = (CACHE_SIZE/sizeof(DTYPE))/sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
  if (!max_hsize) max_hsize = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
  if (max_hsize > BUFF_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    pbuff = mlib_malloc(sizeof(DTYPE)*max_hsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
  sl_c = adr_src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
  dl_c = adr_dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
  for (l = 0; l < hgt; l += hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    hsize = hgt - l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    if (hsize > max_hsize) hsize = max_hsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
      if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
      sl = sl_c + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
      dl = dl_c + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
      for (j = 0; j < hsize; j++) pbuff[j] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
      for (i = 0; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        sl0 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        for (off = 0; off < (n - 4); off += 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
          pk = k + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
          sp = sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
          k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
          p2 = sp[0]; p3 = sp[sll]; p4 = sp[2*sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
          sp += 3*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
          for (j = 0; j < hsize; j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            p4 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            pbuff[j    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            pbuff[j + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
          sl0 += 4*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        pk = k + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        sp = sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        p2 = sp[0]; p3 = sp[sll]; p4 = sp[2*sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        kh = n - off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        if (kh == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
          sp += 3*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            p4 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            dp[0  ] = p0*k0 + p1*k1 + p2*k2 + p3*k3 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            dp[dll] = p1*k0 + p2*k1 + p3*k2 + p4*k3 + pbuff[j + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            dp[0] = p0*k0 + p1*k1 + p2*k2 + p3*k3 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        } else if (kh == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
          sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            p2 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            p3 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            dp[0  ] = p0*k0 + p1*k1 + p2*k2 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            dp[dll] = p1*k0 + p2*k1 + p3*k2 + pbuff[j + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            p2 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            dp[0] = p0*k0 + p1*k1 + p2*k2 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        } else if (kh == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
          sp += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            p1 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            p2 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            dp[0  ] = p0*k0 + p1*k1 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            dp[dll] = p1*k0 + p2*k1 + pbuff[j + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            p1 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            dp[0] = p0*k0 + p1*k1 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        } else /* if (kh == 1) */ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
          for (j = 0; j < hsize; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            p0 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            dp[0] = p0*k0 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            sp += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            dp += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        sl += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        dl += chan1;
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
    sl_c += max_hsize*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    dl_c += max_hsize*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
#define MAX_KER 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
#define MAX_NM  81
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
mlib_status CONV_FUNC(MxN)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                           const mlib_d64   *ker,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                           mlib_s32         m,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                           mlib_s32         n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                           mlib_s32         dm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                           mlib_s32         dn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
  DTYPE k0, k1, k2, k3, k4, k5, k6, *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
  DTYPE p0, p1, p2, p3, p4, p5, p6, p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
  mlib_s32 l, off, kw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
  mlib_s32 chan3 = chan1 + chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
#ifdef TYPE_DOUBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
  const mlib_d64 *k = ker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
  mlib_f32 k_arr[MAX_NM], *k = k_arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
  if (n*m > MAX_NM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    k = mlib_malloc(n*m*sizeof(mlib_f32));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    if (k == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
  for (i = 0; i < n*m; i++) k[i] = (mlib_f32)ker[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
#endif /* TYPE_DOUBLE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
  if (m == 1) return mlib_ImageConv1xN(dst, src, k, n, dn, cmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
  wid -= (m - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
  hgt -= (n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
  adr_dst += dn*dll + dm*chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
      const DTYPE *pk = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
      for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        DTYPE *sp0 = sl + l*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        for (off = 0; off < m; off += kw, pk += kw, sp0 += chan1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
          kw = m - off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
          if (kw > 2*MAX_KER) kw = MAX_KER; else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            if (kw > MAX_KER) kw = kw/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
          p2 = sp0[0]; p3 = sp0[chan1]; p4 = sp0[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
          sp0 += chan3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
          p5 = sp0[0]; p6 = sp0[chan1]; p7 = sp0[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
          k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
          k4 = pk[4]; k5 = pk[5]; k6 = pk[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
          dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
          if (kw == 7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            sp = sp0 += chan3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                p5 = sp[- chan1]; p6 = sp[0]; p7 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                dp[0    ] = p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                dp[chan1] = p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                p5 = sp[- chan1]; p6 = sp[0]; p7 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                dp[0    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                dp[chan1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
          } else if (kw == 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            sp = sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                p5 = sp[0]; p6 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                dp[0    ] = p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                dp[chan1] = p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            } else {
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
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                p5 = sp[0]; p6 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                dp[0    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                dp[chan1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
          } else if (kw == 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            sp = sp0 += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                p0 = p2; p1 = p3; p2 = p4; p3 = p5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                p4 = sp[0]; p5 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                dp[0    ] = p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                dp[chan1] = p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                p0 = p2; p1 = p3; p2 = p4; p3 = p5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                p4 = sp[0]; p5 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                dp[0    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                dp[chan1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
          } else if (kw == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            sp = sp0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                p3 = sp[0]; p4 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                dp[0    ] = p0*k0 + p1*k1 + p2*k2 + p3*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                dp[chan1] = p1*k0 + p2*k1 + p3*k2 + p4*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                p3 = sp[0]; p4 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                dp[0    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                dp[chan1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
          } else if (kw == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            sp = sp0 -= chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                p2 = sp[0]; p3 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                dp[0    ] = p0*k0 + p1*k1 + p2*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                dp[chan1] = p1*k0 + p2*k1 + p3*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                p2 = sp[0]; p3 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                dp[0    ] += p0*k0 + p1*k1 + p2*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                dp[chan1] += p1*k0 + p2*k1 + p3*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
          } else { /* kw == 2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            sp = sp0 -= chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                p1 = sp[0]; p2 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                dp[0    ] = p0*k0 + p1*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                dp[chan1] = p1*k0 + p2*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                p1 = sp[0]; p2 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                dp[0    ] += p0*k0 + p1*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                dp[chan1] += p1*k0 + p2*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
      /* last pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        DTYPE *sp0 = sl + i*chan1, s = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        const DTYPE *pk = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        mlib_s32 x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
          DTYPE *sp = sp0 + l*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
          for (x = 0; x < m; x++) s += sp[x*chan1] * (*pk++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        dp[0] = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
#ifndef TYPE_DOUBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
  if (k != k_arr) mlib_free(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
#endif /* TYPE_DOUBLE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
/***************************************************************/