jdk/src/java.desktop/share/native/libmlib_image/mlib_ImageConvClearEdge_Fp.c
author vadim
Fri, 13 May 2016 11:31:05 +0300
changeset 38415 acea5f7d354b
parent 25859 3317bb8137f4
permissions -rw-r--r--
8047931: Remove unused medialib code Reviewed-by: bae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
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
 * FUNCTIONS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *      mlib_c_ImageConvClearEdge  - Set edge of an image to a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *                                        color. (for float-point image)
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_c_ImageConvClearEdge_Fp(mlib_image     *img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *                                               mlib_s32       dx_l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *                                               mlib_s32       dx_r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *                                               mlib_s32       dy_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *                                               mlib_s32       dy_b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *                                               const mlib_d64 *color,
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
 *      img       Pointer to an 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 cleared.
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 cleared.
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 cleared.
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 cleared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      color     Pointer to the color that the edges are set to.
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
 *      img can have 1, 2, 3 or 4 channels of MLIB_FLOAT or MLIB_DOUBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *      data type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * DESCRIPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *      Set edge of an image to a specific color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *      The unselected channels are not overwritten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *      If src and dst have just one channel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *      cmask is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#include "mlib_image.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#include "mlib_ImageConvEdge.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#define EDGES(chan, type, mask)                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
{                                                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  type *pimg = (type *) mlib_ImageGetData(img);                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  type color_i;                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  mlib_s32 img_stride = mlib_ImageGetStride(img) / sizeof(type);          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  mlib_s32 i, j, l;                                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  mlib_s32 testchan;                                                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  testchan = 1;                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  for (l = chan - 1; l >= 0; l--) {                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    if ((mask & testchan) == 0) {                                         \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
      testchan <<= 1;                                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
      continue;                                                           \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }                                                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    testchan <<= 1;                                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    color_i = (type) color[l];                                            \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    for (j = 0; j < dx_l; j++) {                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      for (i = dy_t; i < (img_height - dy_b); i++) {                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        pimg[i * img_stride + l + j * chan] = color_i;                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      }                                                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }                                                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    for (j = 0; j < dx_r; j++) {                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      for (i = dy_t; i < (img_height - dy_b); i++) {                      \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        pimg[i * img_stride + l + (img_width - 1 - j) * chan] = color_i;  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
      }                                                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }                                                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    for (i = 0; i < dy_t; i++) {                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
      for (j = 0; j < img_width; j++) {                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        pimg[i * img_stride + l + j * chan] = color_i;                    \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
      }                                                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }                                                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    for (i = 0; i < dy_b; i++) {                                          \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
      for (j = 0; j < img_width; j++) {                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        pimg[(img_height - 1 - i) * img_stride + l + j * chan] = color_i; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      }                                                                   \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }                                                                     \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  }                                                                       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
mlib_status mlib_ImageConvClearEdge_Fp(mlib_image     *img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                       mlib_s32       dx_l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                       mlib_s32       dx_r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                       mlib_s32       dy_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                       mlib_s32       dy_b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                       const mlib_d64 *color,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                       mlib_s32       cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  mlib_s32 img_width  = mlib_ImageGetWidth(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  mlib_s32 img_height = mlib_ImageGetHeight(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
  mlib_s32 channel    = mlib_ImageGetChannels(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  if (dx_l + dx_r > img_width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    dx_l = img_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    dx_r = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  if (dy_t + dy_b > img_height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    dy_t = img_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    dy_b = 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 (channel == 1) cmask = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  switch (mlib_ImageGetType(img)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    case MLIB_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
      EDGES(channel,mlib_f32, cmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    case MLIB_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      EDGES(channel,mlib_d64, cmask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
/***************************************************************/