jdk/src/share/native/sun/awt/medialib/mlib_ImageConv2x2_f.c
author jgodinez
Fri, 08 Feb 2013 11:25:42 -0800
changeset 15628 228422512f97
parent 5506 202f599c92aa
permissions -rw-r--r--
8005129: [parfait] #1122 - #1130 native/sun/awt/medialib/mlib_Image*.c Memory leak of pointer 'k' allocated with mlib_malloc Reviewed-by: prr, vadim Contributed-by: jia-hong.chen@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 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_ImageConv2x2 on U8/S16/U16 types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *      and MLIB_EDGE_DST_NO_WRITE mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "mlib_image.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "mlib_ImageConv.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "mlib_c_ImageConv.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#ifdef i386 /* do not copy by mlib_d64 data type for x86 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  mlib_s32 int0, int1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
} two_int;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#define TYPE_64BIT two_int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#else /* i386 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#define TYPE_64BIT mlib_d64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#endif /* i386 ( do not copy by mlib_d64 data type for x86 ) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#define LOAD_KERNEL_INTO_DOUBLE()                                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  while (scalef_expon > 30) {                                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    scalef /= (1 << 30);                                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    scalef_expon -= 30;                                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  }                                                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                                                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  scalef /= (1 << scalef_expon);                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                                                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  /* keep kernel in regs */                                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  k0 = scalef * kern[0];  k1 = scalef * kern[1];  k2 = scalef * kern[2]; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  k3 = scalef * kern[3]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define GET_SRC_DST_PARAMETERS(type)                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  hgt = mlib_ImageGetHeight(src);                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  wid = mlib_ImageGetWidth(src);                                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  nchannel = mlib_ImageGetChannels(src);                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  sll = mlib_ImageGetStride(src) / sizeof(type);                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  dll = mlib_ImageGetStride(dst) / sizeof(type);                \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
  adr_src = (type *)mlib_ImageGetData(src);                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  adr_dst = (type *)mlib_ImageGetData(dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#ifndef MLIB_USE_FTOI_CLAMPING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#define CLAMP_S32(x)                                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  (((x) <= MLIB_S32_MIN) ? MLIB_S32_MIN :                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  (((x) >= MLIB_S32_MAX) ? MLIB_S32_MAX : (mlib_s32)(x)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#define CLAMP_S32(x) ((mlib_s32)(x))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#endif /* MLIB_USE_FTOI_CLAMPING */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#if defined(_LITTLE_ENDIAN) && !defined(_NO_LONGLONG)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
/* NB: Explicit cast to DTYPE is necessary to avoid warning from Microsoft VC compiler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
      And we need to explicitly define cast behavior if source exceeds destination range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      (it is undefined according to C99 spec). We use mask here because this macro is typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
      used to extract bit regions. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#define STORE2(res0, res1)                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  dp[0    ] = (DTYPE) ((res1) & DTYPE_MASK);                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  dp[chan1] = (DTYPE) ((res0) & DTYPE_MASK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
#define STORE2(res0, res1)                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  dp[0    ] = (DTYPE) ((res0) & DTYPE_MASK);                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  dp[chan1] = (DTYPE) ((res1) & DTYPE_MASK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
#endif /* defined(_LITTLE_ENDIAN) && !defined(_NO_LONGLONG) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
#define LOAD_BUFF(buff)                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  buff[i    ] = sp[0];                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
  buff[i + 1] = sp[chan1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#ifdef _LITTLE_ENDIAN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
#define LOAD_BUFF(buff)                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  *(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) | ((mlib_s64)sp[0] & 0xffffffff)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
#else /* _LITTLE_ENDIAN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
#define LOAD_BUFF(buff)                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
  *(mlib_s64*)(buff + i) = (((mlib_s64)sp[0]) << 32) | ((mlib_s64)sp[chan1] & 0xffffffff)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
#endif /* _LITTLE_ENDIAN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
typedef union {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  TYPE_64BIT d64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    mlib_s32 i0, i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  } i32s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
} d64_2x32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
#define D_KER     1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
#define BUFF_LINE 256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
#define XOR_80(x) x ^= 0x80
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
void mlib_ImageXor80_aa(mlib_u8  *dl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                        mlib_s32 wid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                        mlib_s32 hgt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                        mlib_s32 str)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  mlib_u8  *dp, *dend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
  mlib_u32 cadd = 0x80808080;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  mlib_u64 cadd = MLIB_U64_CONST(0x8080808080808080);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
  mlib_s32 j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  if (wid == str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    wid *= hgt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    hgt = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    dend = dl + wid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    for (dp = dl; ((mlib_addr)dp & 7) && (dp < dend); dp++) XOR_80(dp[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    for (; dp <= (dend - 8); dp += 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
      *((mlib_s32*)dp) ^= cadd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      *((mlib_s32*)dp+1) ^= cadd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
      *((mlib_u64*)dp) ^= cadd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    for (; (dp < dend); dp++) XOR_80(dp[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    dl += str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
void mlib_ImageXor80(mlib_u8  *dl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                     mlib_s32 wid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                     mlib_s32 hgt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                     mlib_s32 str,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                     mlib_s32 nchan,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                     mlib_s32 cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
  mlib_s32 i, j, c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    for (c = 0; c < nchan; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
      if (cmask & (1 << (nchan - 1 - c))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        mlib_u8 *dp = dl + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        for (i = 0; i < wid; i++) XOR_80(dp[i*nchan]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    dl += str;
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
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
#define DTYPE mlib_s16
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
#define DTYPE_MASK 0xffff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
mlib_status mlib_c_conv2x2nw_s16(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                 const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                 const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                 mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                 mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
  mlib_d64 buff_arr[2*BUFF_LINE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
  DTYPE    *adr_src, *sl, *sp, *sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
  DTYPE    *adr_dst, *dl, *dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
  mlib_d64 k0, k1, k2, k3, scalef = 65536.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
  mlib_d64 p00, p01, p02,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
           p10, p11, p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
  mlib_s32 wid, hgt, sll, dll, wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  mlib_s32 nchannel, chan1, chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
  mlib_s32 i, j, c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
  LOAD_KERNEL_INTO_DOUBLE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
  wid1 = (wid + 1) &~ 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
  if (wid1 > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
  buffo = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
  buff0 = buffo + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
  buff1 = buff0 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
  buff2 = buff1 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  wid -= D_KER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
  hgt -= D_KER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    sl1 = sl + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    for (i = 0; i < wid + D_KER; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      buff0[i - 1] = (mlib_s32)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    sl += (D_KER + 1)*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
      buff2[-1] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
      sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
      p02 = buff0[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
      p12 = buff1[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        mlib_s32 o64_1, o64_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        mlib_s64 o64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        d64_2x32 sd0, sd1, dd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        p01 = (mlib_d64)sd0.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        p02 = (mlib_d64)sd0.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        p11 = (mlib_d64)sd1.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        p12 = (mlib_d64)sd1.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        LOAD_BUFF(buff2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        *(TYPE_64BIT*)(buffo + i) = dd.d64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        o64_1 = buffo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        o64_2 = buffo[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        STORE2(o64_1 >> 16, o64_2 >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        o64 = *(mlib_s64*)(buffo + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        STORE2(o64 >> 48, o64 >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        p00 = buff0[i - 1]; p10 = buff1[i - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        p01 = buff0[i];     p11 = buff1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        buff2[i] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        dp[0] = buffo[i] >> 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
      buff2 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
mlib_status mlib_c_conv2x2ext_s16(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                  const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                                  mlib_s32         dx_l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                                  mlib_s32         dx_r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                                  mlib_s32         dy_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                                  mlib_s32         dy_b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                                  const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                  mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                                  mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
  mlib_d64 buff_arr[2*BUFF_LINE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
  DTYPE    *adr_src, *sl, *sp, *sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
  DTYPE    *adr_dst, *dl, *dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
  mlib_d64 k0, k1, k2, k3, scalef = 65536.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
  mlib_d64 p00, p01, p02,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
           p10, p11, p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
  mlib_s32 wid, hgt, sll, dll, wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
  mlib_s32 nchannel, chan1, chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
  mlib_s32 i, j, c, swid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
  LOAD_KERNEL_INTO_DOUBLE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
  swid = wid + D_KER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
  wid1 = (swid + 1) &~ 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
  if (wid1 > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
  buffo = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
  buff0 = buffo + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
  buff1 = buff0 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
  buff2 = buff1 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
  swid -= dx_r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    if ((hgt - dy_b) > 0) sl1 = sl + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    else sl1 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    for (i = 0; i < swid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
      buff0[i - 1] = (mlib_s32)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    if (dx_r != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
      buff0[swid - 1] = buff0[swid - 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
      buff1[swid - 1] = buff1[swid - 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    if ((hgt - dy_b) > 1) sl = sl1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    else sl = sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
      buff2[-1] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
      sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
      p02 = buff0[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
      p12 = buff1[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        mlib_s32 o64_1, o64_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        mlib_s64 o64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        d64_2x32 sd0, sd1, dd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        p01 = (mlib_d64)sd0.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        p02 = (mlib_d64)sd0.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        p11 = (mlib_d64)sd1.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        p12 = (mlib_d64)sd1.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        LOAD_BUFF(buff2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        *(TYPE_64BIT*)(buffo + i) = dd.d64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        o64_1 = buffo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        o64_2 = buffo[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        STORE2(o64_1 >> 16, o64_2 >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        o64 = *(mlib_s64*)(buffo + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        STORE2(o64 >> 48, o64 >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        p00 = buff0[i - 1]; p10 = buff1[i - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        p01 = buff0[i];     p11 = buff1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        buff2[i] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        dp[0] = buffo[i] >> 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
      if (dx_r != 0) buff2[swid - 1] = buff2[swid - 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
      if (j < hgt - dy_b - 2) sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
      buff2 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
#undef  DTYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
#define DTYPE mlib_u16
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
mlib_status mlib_c_conv2x2nw_u16(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                                 const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                                 const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                                 mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                                 mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
  mlib_d64 buff_arr[2*BUFF_LINE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
  DTYPE    *adr_src, *sl, *sp, *sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
  DTYPE    *adr_dst, *dl, *dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
  mlib_d64 k0, k1, k2, k3, scalef = 65536.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
  mlib_d64 p00, p01, p02,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
           p10, p11, p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
  mlib_s32 wid, hgt, sll, dll, wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
  mlib_s32 nchannel, chan1, chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
  mlib_s32 i, j, c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
  mlib_d64 doff = 0x7FFF8000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
  LOAD_KERNEL_INTO_DOUBLE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
  wid1 = (wid + 1) &~ 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
  if (wid1 > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
  buffo = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
  buff0 = buffo + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
  buff1 = buff0 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
  buff2 = buff1 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
  wid -= D_KER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
  hgt -= D_KER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    sl1 = sl + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    for (i = 0; i < wid + D_KER; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
      buff0[i - 1] = (mlib_s32)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    sl += (D_KER + 1)*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
      buff2[-1] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
      sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
      p02 = buff0[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
      p12 = buff1[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        mlib_s32 o64_1, o64_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        mlib_s64 o64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        d64_2x32 sd0, sd1, dd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        p01 = (mlib_d64)sd0.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        p02 = (mlib_d64)sd0.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        p11 = (mlib_d64)sd1.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        p12 = (mlib_d64)sd1.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        LOAD_BUFF(buff2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - doff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3 - doff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        *(TYPE_64BIT*)(buffo + i) = dd.d64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        o64_1 = buffo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        o64_2 = buffo[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        o64_1 = o64_1 ^ 0x80000000U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        o64_2 = o64_2 ^ 0x80000000U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        STORE2(o64_1 >> 16, o64_2 >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        o64 = *(mlib_s64*)(buffo + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        o64 = o64 ^ MLIB_U64_CONST(0x8000000080000000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        STORE2(o64 >> 48, o64 >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        p00 = buff0[i - 1]; p10 = buff1[i - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        p01 = buff0[i];     p11 = buff1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        buff2[i] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - doff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        dp[0] = (buffo[i] >> 16) ^ 0x8000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
      buff2 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
mlib_status mlib_c_conv2x2ext_u16(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                                  const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                                  mlib_s32         dx_l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                                  mlib_s32         dx_r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                                  mlib_s32         dy_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                                  mlib_s32         dy_b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                                  const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                                  mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                                  mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
  mlib_d64 buff_arr[2*BUFF_LINE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
  DTYPE    *adr_src, *sl, *sp, *sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
  DTYPE    *adr_dst, *dl, *dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
  mlib_d64 k0, k1, k2, k3, scalef = 65536.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
  mlib_d64 p00, p01, p02,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
           p10, p11, p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
  mlib_s32 wid, hgt, sll, dll, wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
  mlib_s32 nchannel, chan1, chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
  mlib_s32 i, j, c, swid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
  mlib_d64 doff = 0x7FFF8000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
  LOAD_KERNEL_INTO_DOUBLE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
  swid = wid + D_KER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
  wid1 = (swid + 1) &~ 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
  if (wid1 > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
  buffo = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
  buff0 = buffo + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
  buff1 = buff0 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
  buff2 = buff1 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
  swid -= dx_r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    if ((hgt - dy_b) > 0) sl1 = sl + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    else sl1 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    for (i = 0; i < swid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
      buff0[i - 1] = (mlib_s32)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    if (dx_r != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
      buff0[swid - 1] = buff0[swid - 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
      buff1[swid - 1] = buff1[swid - 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    if ((hgt - dy_b) > 1) sl = sl1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    else sl = sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
      buff2[-1] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
      sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
      p02 = buff0[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
      p12 = buff1[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        mlib_s32 o64_1, o64_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        mlib_s64 o64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        d64_2x32 sd0, sd1, dd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        p01 = (mlib_d64)sd0.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        p02 = (mlib_d64)sd0.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        p11 = (mlib_d64)sd1.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        p12 = (mlib_d64)sd1.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        LOAD_BUFF(buff2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - doff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3 - doff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        *(TYPE_64BIT*)(buffo + i) = dd.d64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        o64_1 = buffo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        o64_2 = buffo[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        o64_1 = o64_1 ^ 0x80000000U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        o64_2 = o64_2 ^ 0x80000000U;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        STORE2(o64_1 >> 16, o64_2 >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        o64 = *(mlib_s64*)(buffo + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        o64 = o64 ^ MLIB_U64_CONST(0x8000000080000000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        STORE2(o64 >> 48, o64 >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        p00 = buff0[i - 1]; p10 = buff1[i - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        p01 = buff0[i];     p11 = buff1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        buff2[i] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - doff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        dp[0] = (buffo[i] >> 16) ^ 0x8000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
      if (dx_r != 0) buff2[swid - 1] = buff2[swid - 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
      if (j < hgt - dy_b - 2) sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
      buff2 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
#undef  DTYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
#define DTYPE mlib_u8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
mlib_status mlib_c_conv2x2nw_u8(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                                const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                                const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                                mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                                mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
  mlib_d64 buff_arr[2*BUFF_LINE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
  DTYPE    *adr_src, *sl, *sp, *sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
  DTYPE    *adr_dst, *dl, *dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
  mlib_d64 k0, k1, k2, k3, scalef = (1 << 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
  mlib_d64 p00, p01, p02,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
           p10, p11, p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
  mlib_s32 wid, hgt, sll, dll, wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
  mlib_s32 nchannel, chan1, chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
  mlib_s32 i, j, c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
  LOAD_KERNEL_INTO_DOUBLE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
  wid1 = (wid + 1) &~ 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
  if (wid1 > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
  buffo = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
  buff0 = buffo + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
  buff1 = buff0 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
  buff2 = buff1 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
  wid -= D_KER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
  hgt -= D_KER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    sl1 = sl + sll;
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 + D_KER; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
      buff0[i - 1] = (mlib_s32)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    sl += (D_KER + 1)*sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
      buff2[-1] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
      sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
      p02 = buff0[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
      p12 = buff1[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        mlib_s32 o64_1, o64_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        mlib_s64 o64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        d64_2x32 sd0, sd1, dd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        p01 = (mlib_d64)sd0.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        p02 = (mlib_d64)sd0.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        p11 = (mlib_d64)sd1.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        p12 = (mlib_d64)sd1.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        LOAD_BUFF(buff2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - (1u << 31));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3 - (1u << 31));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        *(TYPE_64BIT*)(buffo + i) = dd.d64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        o64_1 = buffo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        o64_2 = buffo[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        STORE2(o64_1 >> 24, o64_2 >> 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        o64 = *(mlib_s64*)(buffo + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        STORE2(o64 >> 56, o64 >> 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        p00 = buff0[i - 1]; p10 = buff1[i - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        p01 = buff0[i];     p11 = buff1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        buff2[i] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - (1u << 31));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        dp[0] = (buffo[i] >> 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
      sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
      buff2 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    mlib_s32 amask = (1 << nchannel) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    if ((cmask & amask) != amask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
      mlib_ImageXor80(adr_dst, wid, hgt, dll, nchannel, cmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
      mlib_ImageXor80_aa(adr_dst, wid*nchannel, hgt, dll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
mlib_status mlib_c_conv2x2ext_u8(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                                 const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                                 mlib_s32         dx_l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                                 mlib_s32         dx_r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                                 mlib_s32         dy_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                                 mlib_s32         dy_b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                                 const mlib_s32   *kern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                                 mlib_s32         scalef_expon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                                 mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
  mlib_d64 buff_arr[4*BUFF_LINE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
  mlib_s32 *pbuff = (mlib_s32*)buff_arr, *buffo, *buff0, *buff1, *buff2, *buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
  DTYPE    *adr_src, *sl, *sp, *sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
  DTYPE    *adr_dst, *dl, *dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
  mlib_d64 k0, k1, k2, k3, scalef = (1 << 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
  mlib_d64 p00, p01, p02,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
           p10, p11, p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
  mlib_s32 wid, hgt, sll, dll, wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
  mlib_s32 nchannel, chan1, chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
  mlib_s32 i, j, c, swid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
  LOAD_KERNEL_INTO_DOUBLE();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
  GET_SRC_DST_PARAMETERS(DTYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
  swid = wid + D_KER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
  wid1 = (swid + 1) &~ 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
  if (wid1 > BUFF_LINE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    pbuff = mlib_malloc(4*sizeof(mlib_s32)*wid1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    if (pbuff == NULL) return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
  buffo = pbuff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
  buff0 = buffo + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
  buff1 = buff0 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
  buff2 = buff1 + wid1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
  chan1 = nchannel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
  chan2 = chan1 + chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
  swid -= dx_r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
  for (c = 0; c < nchannel; c++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    if (!(cmask & (1 << (nchannel - 1 - c)))) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    sl = adr_src + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    dl = adr_dst + c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    if ((hgt - dy_b) > 0) sl1 = sl + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    else sl1 = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    for (i = 0; i < swid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
      buff0[i - 1] = (mlib_s32)sl[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
      buff1[i - 1] = (mlib_s32)sl1[i*chan1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    if (dx_r != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
      buff0[swid - 1] = buff0[swid - 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
      buff1[swid - 1] = buff1[swid - 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    if ((hgt - dy_b) > 1) sl = sl1 + sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    else sl = sl1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    for (j = 0; j < hgt; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
      sp = sl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
      dp = dl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
      buff2[-1] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
      sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
      p02 = buff0[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
      p12 = buff1[-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
      for (i = 0; i <= (wid - 2); i += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        mlib_s32 o64_1, o64_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        mlib_s64 o64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        d64_2x32 sd0, sd1, dd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        p00 = p02; p10 = p12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        sd0.d64 = *(TYPE_64BIT*)(buff0 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        sd1.d64 = *(TYPE_64BIT*)(buff1 + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        p01 = (mlib_d64)sd0.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        p02 = (mlib_d64)sd0.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        p11 = (mlib_d64)sd1.i32s.i0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        p12 = (mlib_d64)sd1.i32s.i1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        LOAD_BUFF(buff2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        dd.i32s.i0 = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - (1u << 31));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        dd.i32s.i1 = CLAMP_S32(p01 * k0 + p02 * k1 + p11 * k2 + p12 * k3 - (1u << 31));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        *(TYPE_64BIT*)(buffo + i) = dd.d64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
#ifdef _NO_LONGLONG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        o64_1 = buffo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        o64_2 = buffo[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        STORE2(o64_1 >> 24, o64_2 >> 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
#else /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        o64 = *(mlib_s64*)(buffo + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        STORE2(o64 >> 56, o64 >> 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
#endif /* _NO_LONGLONG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        sp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        dp += chan2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
      for (; i < wid; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        p00 = buff0[i - 1]; p10 = buff1[i - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        p01 = buff0[i];     p11 = buff1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        buff2[i] = (mlib_s32)sp[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        buffo[i] = CLAMP_S32(p00 * k0 + p01 * k1 + p10 * k2 + p11 * k3 - (1u << 31));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        dp[0] = (buffo[i] >> 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        sp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        dp += chan1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
      if (dx_r != 0) buff2[swid - 1] = buff2[swid - 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
      if (j < hgt - dy_b - 2) sl += sll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
      dl += dll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
      buffT = buff0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
      buff0 = buff1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
      buff1 = buff2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
      buff2 = buffT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    mlib_s32 amask = (1 << nchannel) - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    if ((cmask & amask) != amask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
      mlib_ImageXor80(adr_dst, wid, hgt, dll, nchannel, cmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
      mlib_ImageXor80_aa(adr_dst, wid*nchannel, hgt, dll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
  if (pbuff != (mlib_s32*)buff_arr) mlib_free(pbuff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
/***************************************************************/