jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_32nw.c
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 15628 228422512f97
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
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: 15628
diff changeset
     2
 * Copyright (c) 2000, 2013, 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 S32 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
#define BUFF_LINE  256
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#define CACHE_SIZE (64*1024)
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 CONV_FUNC(KERN) mlib_conv##KERN##nw_s32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#ifndef MLIB_USE_FTOI_CLAMPING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#define CLAMP_S32(dst, src)                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  if (src > (mlib_d64)MLIB_S32_MAX) src = (mlib_d64)MLIB_S32_MAX; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  if (src < (mlib_d64)MLIB_S32_MIN) src = (mlib_d64)MLIB_S32_MIN; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  dst = (mlib_s32)src
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#define CLAMP_S32(dst, src) dst = (mlib_s32)(src)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#endif /* MLIB_USE_FTOI_CLAMPING */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#define GET_SRC_DST_PARAMETERS(type)                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  mlib_s32 hgt = mlib_ImageGetHeight(src);                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  mlib_s32 wid = mlib_ImageGetWidth(src);                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  mlib_s32 sll = mlib_ImageGetStride(src) / sizeof(type);       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  mlib_s32 dll = mlib_ImageGetStride(dst) / sizeof(type);       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  type*    adr_src = mlib_ImageGetData(src);                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  type*    adr_dst = mlib_ImageGetData(dst);                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  mlib_s32 chan1 = mlib_ImageGetChannels(src)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/*  mlib_s32 chan2 = chan1 + chan1 */
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, *sp, *sl1, *dl, *dp;                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  mlib_d64 *pbuff = buff, *buff0, *buff1, *buff2, *buffT;       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  mlib_s32 i, j, c;                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  mlib_d64 scalef, d0, d1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
#define DEF_VARS_MxN(type)                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  GET_SRC_DST_PARAMETERS(type);                                 \
8939
04615dca2a76 6989717: media native code compiler warnings
bae
parents: 5506
diff changeset
    81
  type     *sl, *sp = NULL, *dl, *dp = NULL;                    \
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  mlib_d64 *pbuff = buff;                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  mlib_s32 i, j, c
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#define CALC_SCALE()                                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  scalef = 1.0;                                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  while (scalef_expon > 30) {                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    scalef /= (1 << 30);                                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    scalef_expon -= 30;                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  }                                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                                                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  scalef /= (1 << scalef_expon)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
#define KSIZE 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
mlib_status CONV_FUNC(2x2)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                           const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                           mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  mlib_d64 buff[(KSIZE + 1)*BUFF_LINE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  mlib_d64 k0, k1, k2, k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  mlib_d64 p00, p01, p02, p03,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
           p10, p11, p12, p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  mlib_d64 d2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  DEF_VARS(mlib_s32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  mlib_s32 chan3 = chan1 + chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
  if (wid > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    pbuff = mlib_malloc((KSIZE + 1)*sizeof(mlib_d64)*wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  buff0 = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
  buff1 = buff0 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
  buff2 = buff1 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  /* keep kernel in regs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  CALC_SCALE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  k0 = scalef * kern[0];  k1 = scalef * kern[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  k2 = scalef * kern[2];  k3 = scalef * kern[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    sl1 = sl + sll;
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 (i = 0; i < wid + (KSIZE - 1); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      buff0[i] = (mlib_d64)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      buff1[i] = (mlib_d64)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    sl += KSIZE*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
      p03 = buff0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
      p13 = buff1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      for (i = 0; i <= (wid - 3); i += 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        p00 = p03; p10 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        p01 = buff0[i + 1]; p11 = buff1[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        p02 = buff0[i + 2]; p12 = buff1[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        p03 = buff0[i + 3]; p13 = buff1[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        buff2[i    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        buff2[i + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        buff2[i + 2] = (mlib_d64)sp[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        d0 = p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        d1 = p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        d2 = p02 * k0 + p03 * k1 + p12 * k2 + p13 * k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        CLAMP_S32(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        CLAMP_S32(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        CLAMP_S32(dp[chan2], d2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        sp += chan3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        dp += chan3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        p00 = buff0[i];     p10 = buff1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        p01 = buff0[i + 1]; p11 = buff1[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        buff2[i] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        d0 = p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        CLAMP_S32(dp[0], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
      buff2[wid] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
      buff2 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
#define KSIZE 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
mlib_status CONV_FUNC(3x3)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                           const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                           mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
  mlib_d64 buff[(KSIZE + 1)*BUFF_LINE], *buff3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
  mlib_d64 k0, k1, k2, k3, k4, k5, k6, k7, k8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
  mlib_d64 p00, p01, p02, p03,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
           p10, p11, p12, p13,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
           p20, p21, p22, p23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
  mlib_s32 *sl2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
  DEF_VARS(mlib_s32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  if (wid > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    pbuff = mlib_malloc((KSIZE + 1)*sizeof(mlib_d64)*wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
  buff0 = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
  buff1 = buff0 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  buff2 = buff1 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
  buff3 = buff2 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
  CALC_SCALE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
  k0 = scalef * kern[0];  k1 = scalef * kern[1];  k2 = scalef * kern[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
  k3 = scalef * kern[3];  k4 = scalef * kern[4];  k5 = scalef * kern[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
  k6 = scalef * kern[6];  k7 = scalef * kern[7];  k8 = scalef * kern[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    sl1 = sl  + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    sl2 = sl1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    for (i = 0; i < wid + (KSIZE - 1); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
      buff0[i] = (mlib_d64)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
      buff1[i] = (mlib_d64)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      buff2[i] = (mlib_d64)sl2[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    sl += KSIZE*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      mlib_d64 s0, s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
      p02 = buff0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
      p12 = buff1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
      p22 = buff2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
      p03 = buff0[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
      p13 = buff1[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
      p23 = buff2[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
      s1 = p03 * k0 + p13 * k3 + p23 * k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        buff3[i    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        buff3[i + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        d0 = s0 + p02 * k2 + p12 * k5 + p22 * k8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        d1 = s1 + p02 * k1 + p03 * k2 + p12 * k4 + p13 * k5 + p22 * k7 + p23 * k8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        CLAMP_S32(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        CLAMP_S32(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        s0 = p02 * k0 + p03 * k1 + p12 * k3 + p13 * k4 + p22 * k6 + p23 * k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        s1 = p03 * k0 + p13 * k3 + p23 * k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        buff3[i] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        d0 = (p00 * k0 + p01 * k1 + p02 * k2 + p10 * k3 + p11 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
              p12 * k5 + p20 * k6 + p21 * k7 + p22 * k8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        CLAMP_S32(dp[0], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
      buff3[wid    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
      buff3[wid + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
      buff2 = buff3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
      buff3 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
#define KSIZE 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
mlib_status CONV_FUNC(4x4)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                           const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                           mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
  mlib_d64 buff[(KSIZE + 2)*BUFF_LINE], *buff3, *buff4, *buff5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
  mlib_d64 k[KSIZE*KSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
  mlib_d64 k0, k1, k2, k3, k4, k5, k6, k7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
  mlib_d64 p00, p01, p02, p03, p04,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
           p10, p11, p12, p13, p14,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
           p20, p21, p22, p23,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
           p30, p31, p32, p33;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
  mlib_s32 *sl2, *sl3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
  DEF_VARS(mlib_s32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
  if (wid > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    pbuff = mlib_malloc((KSIZE + 2)*sizeof(mlib_d64)*wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
  buff0 = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
  buff1 = buff0 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
  buff2 = buff1 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
  buff3 = buff2 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
  buff4 = buff3 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
  buff5 = buff4 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
  CALC_SCALE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
  for (j = 0; j < 16; j++) k[j] = scalef * kern[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    sl1 = sl  + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    sl2 = sl1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    sl3 = sl2 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    for (i = 0; i < wid + (KSIZE - 1); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
      buff0[i] = (mlib_d64)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
      buff1[i] = (mlib_d64)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
      buff2[i] = (mlib_d64)sl2[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
      buff3[i] = (mlib_d64)sl3[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    sl += KSIZE*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
       *  First loop on two first lines of kernel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
      k0 = k[0]; k1 = k[1]; k2 = k[2]; k3 = k[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
      k4 = k[4]; k5 = k[5]; k6 = k[6]; k7 = k[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
      p02 = buff0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
      p12 = buff1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
      p03 = buff0[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
      p13 = buff1[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
      p04 = buff0[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        p02 = p04; p12 = buff1[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        p03 = buff0[i + 3]; p13 = buff1[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        p04 = buff0[i + 4]; p14 = buff1[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        buff4[i] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        buff4[i + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        buff5[i    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                        p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        buff5[i + 1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        p11 * k4 + p12 * k5 + p13 * k6 + p14 * k7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
       *  Second loop on two last lines of kernel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
      k0 = k[ 8]; k1 = k[ 9]; k2 = k[10]; k3 = k[11];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
      k4 = k[12]; k5 = k[13]; k6 = k[14]; k7 = k[15];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
      p02 = buff2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
      p12 = buff3[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
      p03 = buff2[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
      p13 = buff3[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
      p04 = buff2[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        p02 = p04; p12 = buff3[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        p03 = buff2[i + 3]; p13 = buff3[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        p04 = buff2[i + 4]; p14 = buff3[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        d0 = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
              p10 * k4 + p11 * k5 + p12 * k6 + p13 * k7 + buff5[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        d1 = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
              p11 * k4 + p12 * k5 + p13 * k6 + p14 * k7 + buff5[i + 1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        CLAMP_S32(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        CLAMP_S32(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
      /* last pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];     p30 = buff3[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1]; p31 = buff3[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2]; p32 = buff3[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3]; p33 = buff3[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        buff4[i] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        d0 = (p00 * k[0] + p01 * k[1] + p02 * k[2] + p03 * k[3] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
              p10 * k[4] + p11 * k[5] + p12 * k[6] + p13 * k[7] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
              p20 * k[ 8] + p21 * k[ 9] + p22 * k[10] + p23 * k[11] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
              p30 * k[12] + p31 * k[13] + p32 * k[14] + p33 * k[15]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        CLAMP_S32(dp[0], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
      buff4[wid    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
      buff4[wid + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
      buff4[wid + 2] = (mlib_d64)sp[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
      buff2 = buff3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
      buff3 = buff4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
      buff4 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
#define KSIZE 5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
mlib_status CONV_FUNC(5x5)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                           const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                           mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
  mlib_d64 buff[(KSIZE + 2)*BUFF_LINE], *buff3, *buff4, *buff5, *buff6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
  mlib_d64 k[KSIZE*KSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
  mlib_d64 k0, k1, k2, k3, k4, k5, k6, k7, k8, k9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
  mlib_d64 p00, p01, p02, p03, p04, p05,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
           p10, p11, p12, p13, p14, p15,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
           p20, p21, p22, p23, p24,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
           p30, p31, p32, p33, p34,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
           p40, p41, p42, p43, p44;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
  mlib_s32 *sl2, *sl3, *sl4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
  DEF_VARS(mlib_s32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
  mlib_s32 chan3 = chan1 + chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
  if (wid > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    pbuff = mlib_malloc((KSIZE + 2)*sizeof(mlib_d64)*wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
  buff0 = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
  buff1 = buff0 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
  buff2 = buff1 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
  buff3 = buff2 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
  buff4 = buff3 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
  buff5 = buff4 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
  buff6 = buff5 + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
  CALC_SCALE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
  for (j = 0; j < 25; j++) k[j] = scalef * kern[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    sl1 = sl  + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    sl2 = sl1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    sl3 = sl2 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    sl4 = sl3 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    for (i = 0; i < wid + (KSIZE - 1); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
      buff0[i] = (mlib_d64)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
      buff1[i] = (mlib_d64)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
      buff2[i] = (mlib_d64)sl2[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
      buff3[i] = (mlib_d64)sl3[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
      buff4[i] = (mlib_d64)sl4[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    sl += KSIZE*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
       *  First loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
      k0 = k[0]; k1 = k[1]; k2 = k[2]; k3 = k[3]; k4 = k[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
      k5 = k[5]; k6 = k[6]; k7 = k[7]; k8 = k[8]; k9 = k[9];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
      p02 = buff0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
      p12 = buff1[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
      p03 = buff0[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
      p13 = buff1[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
      p04 = buff0[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
      p14 = buff1[2];
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 (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        p02 = p04; p12 = p14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        p03 = buff0[i + 3]; p13 = buff1[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        p04 = buff0[i + 4]; p14 = buff1[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        p05 = buff0[i + 5]; p15 = buff1[i + 5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        buff6[i    ] = (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                        p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        buff6[i + 1] = (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                        p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
       *  Second loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
      k0 = k[10]; k1 = k[11]; k2 = k[12]; k3 = k[13]; k4 = k[14];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
      k5 = k[15]; k6 = k[16]; k7 = k[17]; k8 = k[18]; k9 = k[19];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
      p02 = buff2[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
      p12 = buff3[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
      p03 = buff2[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
      p13 = buff3[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        p01 = p03; p11 = p13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        p02 = buff2[i + 2]; p12 = buff3[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        p03 = buff2[i + 3]; p13 = buff3[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        p04 = buff2[i + 4]; p14 = buff3[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        p05 = buff2[i + 5]; p15 = buff3[i + 5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        buff6[i    ] += (p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                         p10 * k5 + p11 * k6 + p12 * k7 + p13 * k8 + p14 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        buff6[i + 1] += (p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                         p11 * k5 + p12 * k6 + p13 * k7 + p14 * k8 + p15 * k9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
      /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
       *  3 loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
      k0 = k[20]; k1 = k[21]; k2 = k[22]; k3 = k[23]; k4 = k[24];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
      p02 = buff4[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
      p03 = buff4[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
      p04 = buff4[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
      p05 = buff4[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        p00 = p02; p01 = p03; p02 = p04; p03 = p05;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        p04 = buff4[i + 4]; p05 = buff4[i + 5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        buff5[i    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        buff5[i + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        d0 = p00 * k0 + p01 * k1 + p02 * k2 + p03 * k3 + p04 * k4 + buff6[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        d1 = p01 * k0 + p02 * k1 + p03 * k2 + p04 * k3 + p05 * k4 + buff6[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        CLAMP_S32(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        CLAMP_S32(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
      /* last pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        p00 = buff0[i];     p10 = buff1[i];     p20 = buff2[i];     p30 = buff3[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        p01 = buff0[i + 1]; p11 = buff1[i + 1]; p21 = buff2[i + 1]; p31 = buff3[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        p02 = buff0[i + 2]; p12 = buff1[i + 2]; p22 = buff2[i + 2]; p32 = buff3[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        p03 = buff0[i + 3]; p13 = buff1[i + 3]; p23 = buff2[i + 3]; p33 = buff3[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        p04 = buff0[i + 4]; p14 = buff1[i + 4]; p24 = buff2[i + 4]; p34 = buff3[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        p40 = buff4[i];        p41 = buff4[i + 1]; p42 = buff4[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        p43 = buff4[i + 3]; p44 = buff4[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        buff5[i] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        d0 = (p00 * k[0] + p01 * k[1] + p02 * k[2] + p03 * k[3] + p04 * k[4] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
              p10 * k[5] + p11 * k[6] + p12 * k[7] + p13 * k[8] + p14 * k[9] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
              p20 * k[10] + p21 * k[11] + p22 * k[12] + p23 * k[13] + p24 * k[14] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
              p30 * k[15] + p31 * k[16] + p32 * k[17] + p33 * k[18] + p34 * k[19] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
              p40 * k[20] + p41 * k[21] + p42 * k[22] + p43 * k[23] + p44 * k[24]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        CLAMP_S32(dp[0], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
      buff5[wid    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
      buff5[wid + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
      buff5[wid + 2] = (mlib_d64)sp[chan2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
      buff5[wid + 3] = (mlib_d64)sp[chan3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
      buff2 = buff3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
      buff3 = buff4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
      buff4 = buff5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
      buff5 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
#undef  KSIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
#define KSIZE 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
mlib_status CONV_FUNC(7x7)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                           const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                           mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
  mlib_d64 buff[(KSIZE + 2)*BUFF_LINE], *buffs[2*(KSIZE + 1)], *buffd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
  mlib_d64 k[KSIZE*KSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
  mlib_d64 k0, k1, k2, k3, k4, k5, k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
  mlib_d64 p0, p1, p2, p3, p4, p5, p6, p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
  mlib_d64 d0, d1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
  mlib_s32 l, m, buff_ind, *sl2, *sl3, *sl4, *sl5, *sl6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
  mlib_d64 scalef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
  DEF_VARS_MxN(mlib_s32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
  mlib_s32 *sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
  if (wid > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    pbuff = mlib_malloc((KSIZE + 2)*sizeof(mlib_d64)*wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
  for (l = 0; l < KSIZE + 1; l++) buffs[l] = pbuff + l*wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
  for (l = 0; l < KSIZE + 1; l++) buffs[l + (KSIZE + 1)] = buffs[l];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
  buffd = buffs[KSIZE] + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
  wid -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
  hgt -= (KSIZE - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
  adr_dst += ((KSIZE - 1)/2)*(dll + chan1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
  CALC_SCALE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
  for (j = 0; j < 49; j++) k[j] = scalef * kern[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    sl1 = sl  + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    sl2 = sl1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    sl3 = sl2 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    sl4 = sl3 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    sl5 = sl4 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    sl6 = sl5 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    for (i = 0; i < wid + (KSIZE - 1); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
      buffs[0][i] = (mlib_d64)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
      buffs[1][i] = (mlib_d64)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
      buffs[2][i] = (mlib_d64)sl2[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
      buffs[3][i] = (mlib_d64)sl3[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
      buffs[4][i] = (mlib_d64)sl4[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
      buffs[5][i] = (mlib_d64)sl5[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
      buffs[6][i] = (mlib_d64)sl6[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    buff_ind = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    for (i = 0; i < wid; i++) buffd[i] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    sl += KSIZE*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
      mlib_d64 **buffc = buffs + buff_ind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
      mlib_d64 *buffn = buffc[KSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
      mlib_d64 *pk = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
      for (l = 0; l < KSIZE; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        mlib_d64 *buff = buffc[l];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        p5 = buff[3]; p6 = buff[4]; p7 = buff[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        k0 = *pk++; k1 = *pk++; k2 = *pk++; k3 = *pk++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        k4 = *pk++; k5 = *pk++; k6 = *pk++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        if (l < (KSIZE - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
          for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            p6 = buff[i + 6]; p7 = buff[i + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
          for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            p6 = buff[i + 6]; p7 = buff[i + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            buffn[i    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            buffn[i + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            d0 = p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6 + buffd[i    ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            d1 = p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6 + buffd[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            CLAMP_S32(dp[0    ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            CLAMP_S32(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
      /* last pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        mlib_d64 *pk = k, s = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        for (l = 0; l < KSIZE; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
          mlib_d64 *buff = buffc[l] + i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
          for (m = 0; m < KSIZE; m++) s += buff[m] * (*pk++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        CLAMP_S32(dp[0], s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        buffn[i] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
      for (l = 0; l < (KSIZE - 1); l++) buffn[wid + l] = sp[l*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
      buff_ind++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
      if (buff_ind >= KSIZE + 1) buff_ind = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
#define FTYPE  mlib_d64
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
#define DTYPE  mlib_s32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
#define BUFF_SIZE  1600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
static mlib_status mlib_ImageConv1xN(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                                     const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                                     const mlib_d64   *k,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                                     mlib_s32         n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                                     mlib_s32         dn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                                     mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
  FTYPE    buff[BUFF_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
  mlib_s32 off, kh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
  const FTYPE    *pk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
  FTYPE    k0, k1, k2, k3, d0, d1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
  FTYPE    p0, p1, p2, p3, p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
  DTYPE    *sl_c, *dl_c, *sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
  mlib_s32 l, hsize, max_hsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
  DEF_VARS_MxN(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
  hgt -= (n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
  adr_dst += dn*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
  max_hsize = (CACHE_SIZE/sizeof(DTYPE))/sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
  if (!max_hsize) max_hsize = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
  if (max_hsize > BUFF_SIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    pbuff = mlib_malloc(sizeof(FTYPE)*max_hsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
  sl_c = adr_src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
  dl_c = adr_dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
  for (l = 0; l < hgt; l += hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    hsize = hgt - l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    if (hsize > max_hsize) hsize = max_hsize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
      sl = sl_c + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
      dl = dl_c + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
      for (j = 0; j < hsize; j++) pbuff[j] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
      for (i = 0; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        sl0 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        for (off = 0; off < (n - 4); off += 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
          pk = k + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
          sp = sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
          k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
          p2 = sp[0]; p3 = sp[sll]; p4 = sp[2*sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
          sp += 3*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
          for (j = 0; j < hsize; j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            p4 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            pbuff[j    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            pbuff[j + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
          sl0 += 4*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        pk = k + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        sp = sl0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        p2 = sp[0]; p3 = sp[sll]; p4 = sp[2*sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        kh = n - off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        if (kh == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
          sp += 3*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            p4 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            d0 = p0*k0 + p1*k1 + p2*k2 + p3*k3 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            d1 = p1*k0 + p2*k1 + p3*k2 + p4*k3 + pbuff[j + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            CLAMP_S32(dp[0  ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            CLAMP_S32(dp[dll], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            p3 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            d0 = p0*k0 + p1*k1 + p2*k2 + p3*k3 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            CLAMP_S32(dp[0], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        } else if (kh == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
          sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            p2 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            p3 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            d0 = p0*k0 + p1*k1 + p2*k2 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            d1 = p1*k0 + p2*k1 + p3*k2 + pbuff[j + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            CLAMP_S32(dp[0  ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            CLAMP_S32(dp[dll], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            p2 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            d0 = p0*k0 + p1*k1 + p2*k2 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            CLAMP_S32(dp[0], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        } else if (kh == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
          sp += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
          for (j = 0; j <= (hsize - 2); j += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            p1 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            p2 = sp[sll];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            d0 = p0*k0 + p1*k1 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            d1 = p1*k0 + p2*k1 + pbuff[j + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            CLAMP_S32(dp[0  ], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            CLAMP_S32(dp[dll], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            pbuff[j + 1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            sp += 2*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            dp += 2*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
          if (j < hsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            p1 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            d0 = p0*k0 + p1*k1 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            CLAMP_S32(dp[0], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        } else /* if (kh == 1) */ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
          for (j = 0; j < hsize; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            p0 = sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            d0 = p0*k0 + pbuff[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            CLAMP_S32(dp[0], d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            pbuff[j] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            sp += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            dp += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        sl += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        dl += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    sl_c += max_hsize*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    dl_c += max_hsize*dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
  if (pbuff != buff) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
#define MAX_KER 7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
#define MAX_N     15
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
#undef  BUFF_SIZE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
#define BUFF_SIZE 1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
mlib_status CONV_FUNC(MxN)(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                           const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                           const mlib_s32   *kernel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                           mlib_s32         m,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                           mlib_s32         n,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                           mlib_s32         dm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                           mlib_s32         dn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                           mlib_s32         scale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                           mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
  mlib_d64  buff[BUFF_SIZE], *buffs_arr[2*(MAX_N + 1)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
  mlib_d64  **buffs = buffs_arr, *buffd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
  mlib_d64  akernel[256], *k = akernel, fscale = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
  mlib_s32  l, off, kw, bsize, buff_ind, mn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
  mlib_d64  d0, d1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
  mlib_d64  k0, k1, k2, k3, k4, k5, k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
  mlib_d64  p0, p1, p2, p3, p4, p5, p6, p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
  DEF_VARS_MxN(mlib_s32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
  mlib_s32 chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
15628
228422512f97 8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc
jgodinez
parents: 8939
diff changeset
  1163
  mlib_status status = MLIB_SUCCESS;
228422512f97 8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc
jgodinez
parents: 8939
diff changeset
  1164
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
  if (scale > 30) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    fscale *= 1.0/(1 << 30);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    scale -= 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
  fscale /= (1 << scale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
  mn = m*n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
  if (mn > 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    k = mlib_malloc(mn*sizeof(mlib_d64));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    if (k == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
  for (i = 0; i < mn; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    k[i] = kernel[i]*fscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
15628
228422512f97 8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc
jgodinez
parents: 8939
diff changeset
  1184
  if (m == 1) {
228422512f97 8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc
jgodinez
parents: 8939
diff changeset
  1185
    status = mlib_ImageConv1xN(dst, src, k, n, dn, cmask);
228422512f97 8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc
jgodinez
parents: 8939
diff changeset
  1186
    FREE_AND_RETURN_STATUS;
228422512f97 8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc
jgodinez
parents: 8939
diff changeset
  1187
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
  bsize = (n + 2)*wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
  if ((bsize > BUFF_SIZE) || (n > MAX_N)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    pbuff = mlib_malloc(sizeof(mlib_d64)*bsize + sizeof(mlib_d64*)*2*(n + 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
15628
228422512f97 8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc
jgodinez
parents: 8939
diff changeset
  1194
    if (pbuff == NULL) {
228422512f97 8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc
jgodinez
parents: 8939
diff changeset
  1195
      status = MLIB_FAILURE;
228422512f97 8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc
jgodinez
parents: 8939
diff changeset
  1196
      FREE_AND_RETURN_STATUS;
228422512f97 8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc
jgodinez
parents: 8939
diff changeset
  1197
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
    buffs = (mlib_d64**)(pbuff + bsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
  for (l = 0; l < (n + 1); l++) buffs[l] = pbuff + l*wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
  for (l = 0; l < (n + 1); l++) buffs[l + (n + 1)] = buffs[l];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
  buffd = buffs[n] + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
  wid -= (m - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
  hgt -= (n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
  adr_dst += dn*dll + dm*chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
  for (c = 0; c < chan1; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    if (!(cmask & (1 << (chan1 - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
      mlib_d64 *buff = buffs[l];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
      for (i = 0; i < wid + (m - 1); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        buff[i] = (mlib_d64)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    buff_ind = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    for (i = 0; i < wid; i++) buffd[i] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
      mlib_d64 **buffc = buffs + buff_ind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
      mlib_d64 *buffn = buffc[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
      mlib_d64 *pk = k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
      for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        mlib_d64 *buff_l = buffc[l];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        for (off = 0; off < m;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
          mlib_d64 *buff = buff_l + off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
          kw = m - off;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
          if (kw > 2*MAX_KER) kw = MAX_KER; else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            if (kw > MAX_KER) kw = kw/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
          off += kw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
          sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
          dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
          p2 = buff[0]; p3 = buff[1]; p4 = buff[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
          p5 = buff[3]; p6 = buff[4]; p7 = buff[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
          k0 = pk[0]; k1 = pk[1]; k2 = pk[2]; k3 = pk[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
          k4 = pk[4]; k5 = pk[5]; k6 = pk[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
          pk += kw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
          if (kw == 7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                p6 = buff[i + 6]; p7 = buff[i + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6; p5 = p7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                p6 = buff[i + 6]; p7 = buff[i + 7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                buffn[i    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                buffn[i + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                d0 = p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + p6*k6 + buffd[i    ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                d1 = p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + p7*k6 + buffd[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                CLAMP_S32(dp[0],     d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                CLAMP_S32(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
          } else if (kw == 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                p5 = buff[i + 5]; p6 = buff[i + 6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                p0 = p2; p1 = p3; p2 = p4; p3 = p5; p4 = p6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                p5 = buff[i + 5]; p6 = buff[i + 6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                buffn[i    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                buffn[i + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                d0 = p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + p5*k5 + buffd[i    ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                d1 = p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + p6*k5 + buffd[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                CLAMP_S32(dp[0],     d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                CLAMP_S32(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
          } else if (kw == 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                p0 = p2; p1 = p3; p2 = p4; p3 = p5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                p4 = buff[i + 4]; p5 = buff[i + 5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                p0 = p2; p1 = p3; p2 = p4; p3 = p5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                p4 = buff[i + 4]; p5 = buff[i + 5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                buffn[i    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                buffn[i + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                d0 = p0*k0 + p1*k1 + p2*k2 + p3*k3 + p4*k4 + buffd[i    ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                d1 = p1*k0 + p2*k1 + p3*k2 + p4*k3 + p5*k4 + buffd[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                CLAMP_S32(dp[0],     d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                CLAMP_S32(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
          } else if (kw == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                p3 = buff[i + 3]; p4 = buff[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2 + p3*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2 + p4*k3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                p0 = p2; p1 = p3; p2 = p4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                p3 = buff[i + 3]; p4 = buff[i + 4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                buffn[i    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                buffn[i + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                d0 = p0*k0 + p1*k1 + p2*k2 + p3*k3 + buffd[i    ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                d1 = p1*k0 + p2*k1 + p3*k2 + p4*k3 + buffd[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                CLAMP_S32(dp[0],     d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                CLAMP_S32(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
          } else if (kw == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                p2 = buff[i + 2]; p3 = buff[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                buffd[i    ] += p0*k0 + p1*k1 + p2*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                buffd[i + 1] += p1*k0 + p2*k1 + p3*k2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                p0 = p2; p1 = p3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                p2 = buff[i + 2]; p3 = buff[i + 3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                buffn[i    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                buffn[i + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                d0 = p0*k0 + p1*k1 + p2*k2 + buffd[i    ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                d1 = p1*k0 + p2*k1 + p3*k2 + buffd[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                CLAMP_S32(dp[0],     d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                CLAMP_S32(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
          } else { /* kw == 2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            if (l < (n - 1) || off < m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                p1 = buff[i + 1]; p2 = buff[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                buffd[i    ] += p0*k0 + p1*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                buffd[i + 1] += p1*k0 + p2*k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
              for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                p0 = p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                p1 = buff[i + 1]; p2 = buff[i + 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                buffn[i    ] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                buffn[i + 1] = (mlib_d64)sp[chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                d0 = p0*k0 + p1*k1 + buffd[i    ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                d1 = p1*k0 + p2*k1 + buffd[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                CLAMP_S32(dp[0],     d0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                CLAMP_S32(dp[chan1], d1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                buffd[i    ] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                buffd[i + 1] = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
      /* last pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        mlib_d64 *pk = k, s = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        mlib_s32 x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        for (l = 0; l < n; l++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
          mlib_d64 *buff = buffc[l] + i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
          for (x = 0; x < m; x++) s += buff[x] * (*pk++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        CLAMP_S32(dp[0], s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        buffn[i] = (mlib_d64)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
      for (l = 0; l < (m - 1); l++) buffn[wid + l] = sp[l*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
      /* next line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
      buff_ind++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
      if (buff_ind >= n + 1) buff_ind = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
15628
228422512f97 8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc
jgodinez
parents: 8939
diff changeset
  1542
  FREE_AND_RETURN_STATUS;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
/***************************************************************/