jdk/src/java.desktop/share/native/libmlib_image/mlib_ImageConv_D64nw.c
author vadim
Fri, 13 May 2016 11:31:05 +0300
changeset 38415 acea5f7d354b
parent 25859 3317bb8137f4
permissions -rw-r--r--
8047931: Remove unused medialib code Reviewed-by: bae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 8939
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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;                                                 \
8939
04615dca2a76 6989717: media native code compiler warnings
bae
parents: 5506
diff changeset
    74
  type     *dl, *dp = NULL;                                     \
04615dca2a76 6989717: media native code compiler warnings
bae
parents: 5506
diff changeset
    75
  mlib_s32 i = 0, j, c
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#define BUFF_SIZE  1600
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#define CACHE_SIZE (64*1024)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
static mlib_status mlib_ImageConv1xN(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                     const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                     const DTYPE      *k,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                     mlib_s32         n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                     mlib_s32         dn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                     mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  DTYPE    buff[BUFF_SIZE], *pbuff = buff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  const DTYPE    *pk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  DTYPE    k0, k1, k2, k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  DTYPE    p0, p1, p2, p3, p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  DTYPE    *sp, *sl_c, *dl_c, *sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  mlib_s32 off, kh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  mlib_s32 l, hsize, max_hsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  hgt -= (n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  adr_dst += dn*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  max_hsize = (CACHE_SIZE/sizeof(DTYPE))/sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  if (!max_hsize) max_hsize = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  if (max_hsize > BUFF_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    pbuff = mlib_malloc(sizeof(DTYPE)*max_hsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  sl_c = adr_src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  dl_c = adr_dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  for (l = 0; l < hgt; l += hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    hsize = hgt - l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    if (hsize > max_hsize) hsize = max_hsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      sl = sl_c + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
      dl = dl_c + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
      for (j = 0; j < hsize; j++) pbuff[j] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      for (i = 0; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        sl0 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        for (off = 0; off < (n - 4); off += 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
          pk = k + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
          sp = sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
          k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
          p2 = sp[0]; p3 = sp[sll]; p4 = sp[2*sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
          sp += 3*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
          for (j = 0; j < hsize; j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            p4 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            pbuff[j    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            pbuff[j + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
          sl0 += 4*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        pk = k + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        sp = sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        p2 = sp[0]; p3 = sp[sll]; p4 = sp[2*sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        kh = n - off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (kh == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
          sp += 3*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            p4 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            dp[0  ] = p0*k0 + p1*k1 + p2*k2 + p3*k3 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            dp[dll] = p1*k0 + p2*k1 + p3*k2 + p4*k3 + pbuff[j + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            dp[0] = p0*k0 + p1*k1 + p2*k2 + p3*k3 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        } else if (kh == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
          sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            p2 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            p3 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            dp[0  ] = p0*k0 + p1*k1 + p2*k2 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            dp[dll] = p1*k0 + p2*k1 + p3*k2 + pbuff[j + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            p2 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            dp[0] = p0*k0 + p1*k1 + p2*k2 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        } else if (kh == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
          sp += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            p1 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            p2 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            dp[0  ] = p0*k0 + p1*k1 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            dp[dll] = p1*k0 + p2*k1 + pbuff[j + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            p1 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            dp[0] = p0*k0 + p1*k1 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        } else /* if (kh == 1) */ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
          for (j = 0; j < hsize; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            p0 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            dp[0] = p0*k0 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            sp += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            dp += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        sl += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        dl += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    sl_c += max_hsize*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    dl_c += max_hsize*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
#define MAX_KER 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
#define MAX_NM  81
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
mlib_status CONV_FUNC(MxN)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                           const mlib_d64   *ker,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                           mlib_s32         m,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                           mlib_s32         n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                           mlib_s32         dm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                           mlib_s32         dn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
  DTYPE k0, k1, k2, k3, k4, k5, k6, *sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
  DTYPE p0, p1, p2, p3, p4, p5, p6, p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
  mlib_s32 l, off, kw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
  DEF_VARS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
  mlib_s32 chan3 = chan1 + chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
#ifdef TYPE_DOUBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
  const mlib_d64 *k = ker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
  mlib_f32 k_arr[MAX_NM], *k = k_arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
  if (n*m > MAX_NM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    k = mlib_malloc(n*m*sizeof(mlib_f32));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    if (k == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
  for (i = 0; i < n*m; i++) k[i] = (mlib_f32)ker[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
#endif /* TYPE_DOUBLE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
  if (m == 1) return mlib_ImageConv1xN(dst, src, k, n, dn, cmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
  wid -= (m - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
  hgt -= (n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
  adr_dst += dn*dll + dm*chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
      const DTYPE *pk = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
      for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        DTYPE *sp0 = sl + l*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        for (off = 0; off < m; off += kw, pk += kw, sp0 += chan1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
          kw = m - off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
          if (kw > 2*MAX_KER) kw = MAX_KER; else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (kw > MAX_KER) kw = kw/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
          p2 = sp0[0]; p3 = sp0[chan1]; p4 = sp0[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
          sp0 += chan3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
          p5 = sp0[0]; p6 = sp0[chan1]; p7 = sp0[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
          k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
          k4 = pk[4]; k5 = pk[5]; k6 = pk[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
          dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
          if (kw == 7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            sp = sp0 += chan3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                p5 = sp[- chan1]; p6 = sp[0]; p7 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                dp[0    ] = p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                dp[chan1] = p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                p5 = sp[- chan1]; p6 = sp[0]; p7 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                dp[0    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                dp[chan1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
          } else if (kw == 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            sp = sp0 += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                p5 = sp[0]; p6 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                dp[0    ] = p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                dp[chan1] = p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                p5 = sp[0]; p6 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                dp[0    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                dp[chan1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
          } else if (kw == 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            sp = sp0 += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                p0 = p2; p1 = p3; p2 = p4; p3 = p5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                p4 = sp[0]; p5 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                dp[0    ] = p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                dp[chan1] = p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                p0 = p2; p1 = p3; p2 = p4; p3 = p5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                p4 = sp[0]; p5 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                dp[0    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                dp[chan1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
          } else if (kw == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            sp = sp0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                p3 = sp[0]; p4 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                dp[0    ] = p0*k0 + p1*k1 + p2*k2 + p3*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                dp[chan1] = p1*k0 + p2*k1 + p3*k2 + p4*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                p3 = sp[0]; p4 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                dp[0    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                dp[chan1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
          } else if (kw == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            sp = sp0 -= chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                p2 = sp[0]; p3 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                dp[0    ] = p0*k0 + p1*k1 + p2*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                dp[chan1] = p1*k0 + p2*k1 + p3*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                p2 = sp[0]; p3 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                dp[0    ] += p0*k0 + p1*k1 + p2*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                dp[chan1] += p1*k0 + p2*k1 + p3*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
          } else { /* kw == 2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            sp = sp0 -= chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            if (pk == k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                p1 = sp[0]; p2 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                dp[0    ] = p0*k0 + p1*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                dp[chan1] = p1*k0 + p2*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                p1 = sp[0]; p2 = sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                dp[0    ] += p0*k0 + p1*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                dp[chan1] += p1*k0 + p2*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
      /* last pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
      if (wid & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        DTYPE *sp0 = sl + i*chan1, s = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        const DTYPE *pk = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        mlib_s32 x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
          DTYPE *sp = sp0 + l*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
          for (x = 0; x < m; x++) s += sp[x*chan1] * (*pk++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        dp[0] = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
#ifndef TYPE_DOUBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
  if (k != k_arr) mlib_free(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
#endif /* TYPE_DOUBLE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
/***************************************************************/