jdk/src/solaris/native/sun/awt/medialib/mlib_ImageConvCopyEdge_Fp.c
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * FUNCTIONS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *      mlib_ImageConvCopyEdge_Fp  - Copy src edges  to dst edges
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * SYNOPSIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *      mlib_status mlib_ImageConvCopyEdge_Fp(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *                                            const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *                                            mlib_s32         dx_l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *                                            mlib_32          dx_r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *                                            mlib_s32         dy_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *                                            mlib_32          dy_b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *                                            mlib_s32         cmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * ARGUMENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *      dst       Pointer to an dst image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *      src       Pointer to an src image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      dx_l      Number of columns on the left side of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *                image to be copyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      dx_r      Number of columns on the right side of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *                image to be copyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      dy_t      Number of rows on the top edge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *                image to be copyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *      dy_b      Number of rows on the top edge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *                image to be copyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      cmask     Channel mask to indicate the channels to be convolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *                Each bit of which represents a channel in the image. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *                channels corresponded to 1 bits are those to be processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * RESTRICTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *      The src and the dst must be the same type, same width, same height and have same number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *      of channels (1, 2, 3, or 4). The unselected channels are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *      overwritten. If both src and dst have just one channel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *      cmask is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * DESCRIPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *      Copy src edges  to dst edges.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *      The unselected channels are not overwritten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *      If src and dst have just one channel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *      cmask is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#include "mlib_image.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#include "mlib_ImageConvEdge.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#define EDGES(chan, type, mask)                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
{                                                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  type *pdst = (type *) mlib_ImageGetData(dst);                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  type *psrc = (type *) mlib_ImageGetData(src);                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  mlib_s32 dst_stride = mlib_ImageGetStride(dst) / sizeof(type);  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  mlib_s32 src_stride = mlib_ImageGetStride(src) / sizeof(type);  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  mlib_s32 i, j, l;                                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  mlib_s32 testchan;                                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  testchan = 1;                                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  for (l = chan - 1; l >= 0; l--) {                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    if ((mask & testchan) == 0) {                                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
      testchan <<= 1;                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
      continue;                                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }                                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    testchan <<= 1;                                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    for (j = 0; j < dx_l; j++) {                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      for (i = dy_t; i < (img_height - dy_b); i++) {              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        pdst[i * dst_stride + l + j * chan] =                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
          psrc[i * src_stride + l + j * chan];                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }                                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    for (j = 0; j < dx_r; j++) {                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
      for (i = dy_t; i < (img_height - dy_b); i++) {              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        pdst[i * dst_stride + l + (img_width - 1 - j) * chan] =   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
          psrc[i * src_stride + l + (img_width - 1 - j) * chan];  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }                                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    for (i = 0; i < dy_t; i++) {                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
      for (j = 0; j < img_width; j++) {                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        pdst[i * dst_stride + l + j * chan] =                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
          psrc[i * src_stride + l + j * chan];                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }                                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    for (i = 0; i < dy_b; i++) {                                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      for (j = 0; j < img_width; j++) {                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        pdst[(img_height - 1 - i) * dst_stride + l + j * chan] =  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
          psrc[(img_height - 1 - i) * src_stride + l + j * chan]; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      }                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }                                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
  }                                                               \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
mlib_status mlib_ImageConvCopyEdge_Fp(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                      const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                      mlib_s32         dx_l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                      mlib_s32         dx_r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                      mlib_s32         dy_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                      mlib_s32         dy_b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                      mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
  mlib_s32 img_width  = mlib_ImageGetWidth(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  mlib_s32 img_height = mlib_ImageGetHeight(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  mlib_s32 channel    = mlib_ImageGetChannels(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  if (dx_l + dx_r > img_width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    dx_l = img_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    dx_r = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  if (dy_t + dy_b > img_height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    dy_t = img_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    dy_b = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
  if (channel == 1) cmask = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  switch (mlib_ImageGetType(src)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    case MLIB_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      EDGES(channel,mlib_f32, cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    case MLIB_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
      EDGES(channel,mlib_d64, cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
/***************************************************************/