jdk/src/share/native/sun/awt/medialib/mlib_ImageConvClearEdge_Bit.c
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 5506 202f599c92aa
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
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_ImageConvClearEdge_BIt  - Set edge of an bit type image to a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *                                     color.
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_ImageConvClearEdge_Bit(mlib_image     *img,
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
 *                                              const mlib_s32 *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 channels of MLIB_BIT data type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * DESCRIPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *      Set edge of an image to a specific color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *      The unselected channels are not overwritten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *      If src and dst have just one channel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *      cmask is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#include "mlib_image.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#include "mlib_ImageConvEdge.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
mlib_status mlib_ImageConvClearEdge_Bit(mlib_image     *img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                        mlib_s32       dx_l,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                        mlib_s32       dx_r,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                        mlib_s32       dy_t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                        mlib_s32       dy_b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                        const mlib_s32 *color,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                        mlib_s32       cmask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  mlib_u8  *pimg = mlib_ImageGetData(img), *pd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  mlib_s32 img_height = mlib_ImageGetHeight(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  mlib_s32 img_width  = mlib_ImageGetWidth(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  mlib_s32 img_stride = mlib_ImageGetStride(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  mlib_s32 bitoff = mlib_ImageGetBitOffset(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  mlib_s32 bitoff_end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  mlib_u8  color_i, mask, mask_end, tmp_color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  mlib_u8  tmp_start, tmp_end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  mlib_s32 i, j, amount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  if ((mlib_ImageGetType(img) != MLIB_BIT) || (mlib_ImageGetChannels(img) != 1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  color_i = (mlib_u8)(color[0] & 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  color_i |= (color_i << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  color_i |= (color_i << 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  color_i |= (color_i << 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  pd = pimg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  if (dx_l > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    if (bitoff + dx_l <= 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
      mask = (0xFF >> bitoff) & (0xFF << ((8 - (bitoff + dx_l)) & 7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
      tmp_color = color_i & mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
      mask = ~mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      for (i = dy_t; i < (img_height - dy_b); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        pd[i*img_stride] = (pd[i*img_stride] & mask) | tmp_color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
      mask = (0xFF >> bitoff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
      tmp_color = color_i & mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      mask = ~mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      for (i = dy_t; i < (img_height - dy_b); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        pd[i*img_stride] = (pd[i*img_stride] & mask) | tmp_color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      amount = (bitoff + dx_l + 7) >> 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      mask = (0xFF << ((8 - (bitoff + dx_l)) & 7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
      tmp_color = color_i & mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      mask = ~mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
      for (j = 1; j < amount - 1; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        for (i = dy_t; i < (img_height - dy_b); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
          pd[i*img_stride + j] = color_i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      for (i = dy_t; i < (img_height - dy_b); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        pd[i*img_stride + amount - 1] = (pd[i*img_stride + amount - 1] & mask) | tmp_color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
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 (dx_r > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    pd = pimg + (img_width + bitoff - dx_r) / 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    bitoff = (img_width + bitoff - dx_r) & 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    if (bitoff + dx_r <= 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
      mask = (0xFF >> bitoff) & (0xFF << ((8 - (bitoff + dx_r)) & 7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      tmp_color = color_i & mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      mask = ~mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      for (i = dy_t; i < (img_height - dy_b); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        pd[i*img_stride] = (pd[i*img_stride] & mask) | tmp_color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
      mask = (0xFF >> bitoff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      tmp_color = color_i & mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
      mask = ~mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
      for (i = dy_t; i < (img_height - dy_b); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        pd[i*img_stride] = (pd[i*img_stride] & mask) | tmp_color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
      amount = (bitoff + dx_r + 7) >> 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
      mask = (0xFF << ((8 - (bitoff + dx_r)) & 7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
      tmp_color = color_i & mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      mask = ~mask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
      for (j = 1; j < amount - 1; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        for (i = dy_t; i < (img_height - dy_b); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
          pd[i*img_stride + j] = color_i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      for (i = dy_t; i < (img_height - dy_b); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        pd[i*img_stride + amount - 1] = (pd[i*img_stride + amount - 1] & mask) | tmp_color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  bitoff = mlib_ImageGetBitOffset(img);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
  bitoff_end = (bitoff + img_width) & 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
  amount = (bitoff + img_width + 7) >> 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
  mask = (0xFF >> bitoff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
  mask_end = (0xFF << ((8 - bitoff_end) & 7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  pd = pimg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
  for (i = 0; i < dy_t; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    tmp_start = pd[i*img_stride];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    tmp_end = pd[i*img_stride+amount-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    for (j = 0; j < amount; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      pd[i*img_stride + j] = color_i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    pd[i*img_stride] = (tmp_start & (~mask)) | (pd[i*img_stride] & mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    pd[i*img_stride+amount-1] = (tmp_end & (~mask_end)) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                (pd[i*img_stride+amount-1] & mask_end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
  pd = pimg + (img_height-1)*img_stride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
  for (i = 0; i < dy_b; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    tmp_start = pd[-i*img_stride];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    tmp_end = pd[-i*img_stride+amount-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    for (j = 0; j < amount; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     pd[-i*img_stride + j] = color_i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    pd[-i*img_stride] = (tmp_start & (~mask)) | (pd[-i*img_stride] & mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    pd[-i*img_stride+amount-1] = (tmp_end & (~mask_end)) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                 (pd[-i*img_stride+amount-1] & mask_end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
/***************************************************************/