src/java.desktop/share/native/libmlib_image/mlib_c_ImageConvCopyEdge.c
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.desktop/share/native/libmlib_image/mlib_c_ImageConvCopyEdge.c@3317bb8137f4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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) 1997, 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
 * FUNCTIONS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *      mlib_ImageConvCopyEdge  - Copy src edges to dst edges
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * SYNOPSIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *      mlib_status mlib_ImageConvCopyEdge(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *                                         const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *                                         mlib_s32         dx_l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *                                         mlib_s32         dx_r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *                                         mlib_s32         dy_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *                                         mlib_s32         dy_b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *                                         mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * ARGUMENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *      dst       Pointer to an dst image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      src       Pointer to an src image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *      dx_l      Number of columns on the left side of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *                image to be copyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      dx_r      Number of columns on the right side of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *                image to be copyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      dy_t      Number of rows on the top edge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *                image to be copyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *      dy_b      Number of rows on the top edge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *                image to be copyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *      cmask     Channel mask to indicate the channels to be convolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *                Each bit of which represents a channel in the image. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *                channels corresponded to 1 bits are those to be processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * RESTRICTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *      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
    58
 *      of channels (1, 2, 3, or 4). The unselected channels are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *      overwritten. If both src and dst have just one channel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *      cmask is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * DESCRIPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *      Copy src edges  to dst edges.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *      The unselected channels are not overwritten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *      If src and dst have just one channel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *      cmask is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#include "mlib_image.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#include "mlib_ImageConvEdge.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#define EDGES(chan, type, mask)                                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  {                                                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    type *pdst = (type *) mlib_ImageGetData(dst);                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    type *psrc = (type *) mlib_ImageGetData(src);                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    mlib_s32 dst_stride = mlib_ImageGetStride(dst) / sizeof(type);           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    mlib_s32 src_stride = mlib_ImageGetStride(src) / sizeof(type);           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    mlib_s32 i, j, l;                                                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    mlib_s32 testchan;                                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                                                             \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    testchan = 1;                                                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    for (l = chan - 1; l >= 0; l--) {                                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
      if ((mask & testchan) == 0) {                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        testchan <<= 1;                                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        continue;                                                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      }                                                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      testchan <<= 1;                                                        \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      for (j = 0; j < dx_l; j++) {                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        for (i = dy_t; i < (img_height - dy_b); i++) {                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
          pdst[i*dst_stride + l + j*chan] = 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] = psrc[i*src_stride + l + j*chan]; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }                                                                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      }                                                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      for (i = 0; i < dy_b; i++) {                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        for (j = 0; j < img_width; j++) {                                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
          pdst[(img_height-1 - i)*dst_stride + l + j*chan] =                 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
          psrc[(img_height-1 - i)*src_stride + l + j*chan];                  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }                                                                    \
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
mlib_status mlib_ImageConvCopyEdge(mlib_image       *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                   const mlib_image *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                   mlib_s32         dx_l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                   mlib_s32         dx_r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                   mlib_s32         dy_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                   mlib_s32         dy_b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                   mlib_s32         cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  mlib_s32 img_width = mlib_ImageGetWidth(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
  mlib_s32 img_height = mlib_ImageGetHeight(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  mlib_s32 channel = mlib_ImageGetChannels(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  if (dx_l + dx_r > img_width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    dx_l = img_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    dx_r = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  if (dy_t + dy_b > img_height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    dy_t = img_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    dy_b = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  if (channel == 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    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_BIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      return mlib_ImageConvCopyEdge_Bit(dst, src, dx_l, dx_r, dy_t, dy_b, cmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    case MLIB_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      EDGES(channel, mlib_u8, cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    case MLIB_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    case MLIB_USHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      EDGES(channel, mlib_u16, cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    case MLIB_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    case MLIB_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
      EDGES(channel, mlib_u32, cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    case MLIB_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
      EDGES(channel, mlib_d64, cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
/***************************************************************/