jdk/src/java.desktop/unix/native/libawt/awt/medialib/mlib_v_ImageCopy.c
author prr
Fri, 19 Sep 2014 09:41:05 -0700
changeset 26751 70bac69b37c9
parent 25859 jdk/src/java.desktop/unix/native/libawt/sun/awt/medialib/mlib_v_ImageCopy.c@3317bb8137f4
permissions -rw-r--r--
8056216: Remove "sun" directory layer from libawt and common Reviewed-by: erikj, ihse, coffeys
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) 2000, 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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * FUNCTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *      mlib_ImageCopy   - Direct copy from one image to another.
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_ImageCopy(mlib_image *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *                                 mlib_image *src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * ARGUMENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *      dst     pointer to output or destination image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *      src     pointer to input or source image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * RESTRICTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *      src and dst must have the same size, type and number of channels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *      They can have 1, 2, 3 or 4 channels of MLIB_BIT, MLIB_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      MLIB_SHORT, MLIB_INT, MLIB_FLOAT or MLIB_DOUBLE data type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * DESCRIPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      Direct copy from one image to another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include "mlib_image.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#include "mlib_ImageCheck.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
extern void mlib_v_ImageCopy_blk(mlib_u8 *sa, mlib_u8 *da, mlib_s32 size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
extern void mlib_v_ImageCopy_a1(mlib_d64 *sp, mlib_d64 *dp, mlib_s32 size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
extern void mlib_ImageCopy_na(mlib_u8 *sa, mlib_u8 *da, mlib_s32 size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
extern void mlib_ImageCopy_bit_al(mlib_u8 *sa, mlib_u8 *da,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                                  mlib_s32 size, mlib_s32 offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
extern void mlib_ImageCopy_bit_na(mlib_u8 *sa, mlib_u8 *da, mlib_s32 size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                                  mlib_s32 s_offset, mlib_s32 d_offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#ifdef MLIB_TEST
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
mlib_status mlib_v_ImageCopy(mlib_image *dst, mlib_image *src)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
mlib_status mlib_ImageCopy(mlib_image *dst, const mlib_image *src)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  mlib_u8  *sa;         /* start point in source */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  mlib_u8  *da;         /* start points in destination */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  mlib_s32 width;       /* width in bytes of src and dst */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  mlib_s32 height;      /* height in lines of src and dst */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  mlib_s32 s_offset;    /* bit offset of src */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  mlib_s32 d_offset;    /* bit offset of dst */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  mlib_s32 stride;      /* stride in bytes in src*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  mlib_s32 dstride;     /* stride in bytes in dst */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  mlib_s32 j;           /* indices for x, y */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  mlib_s32 size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  MLIB_IMAGE_CHECK(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  MLIB_IMAGE_CHECK(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  MLIB_IMAGE_TYPE_EQUAL(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  MLIB_IMAGE_CHAN_EQUAL(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  MLIB_IMAGE_SIZE_EQUAL(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  width  = mlib_ImageGetWidth(dst) * mlib_ImageGetChannels(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  height = mlib_ImageGetHeight(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  sa = (mlib_u8 *)mlib_ImageGetData(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  da = (mlib_u8 *)mlib_ImageGetData(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  switch (mlib_ImageGetType(dst)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    case MLIB_BIT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
      if (!mlib_ImageIsNotOneDvector(src) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
          !mlib_ImageIsNotOneDvector(dst)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
          size = height * (width  >> 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
          if ((size & 0x3f) == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
              !mlib_ImageIsNotAligned64(src) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
              !mlib_ImageIsNotAligned64(dst)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
              mlib_v_ImageCopy_blk(sa, da, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
              return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
          if (((size & 7) == 0) && !mlib_ImageIsNotAligned8(src) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
              !mlib_ImageIsNotAligned8(dst)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
              size >>= 3;                                /* in octlet */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
              mlib_v_ImageCopy_a1((mlib_d64 *)sa, (mlib_d64 *)da, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
          else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            mlib_ImageCopy_na(sa, da, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
      else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        stride = mlib_ImageGetStride(src);                /* in byte */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        dstride = mlib_ImageGetStride(dst);               /* in byte */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        s_offset = mlib_ImageGetBitOffset(src);           /* in bits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        d_offset = mlib_ImageGetBitOffset(dst);           /* in bits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (s_offset == d_offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
          for (j = 0; j < height; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            mlib_ImageCopy_bit_al(sa, da, width, s_offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            sa += stride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            da += dstride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
          for (j = 0; j < height; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            mlib_ImageCopy_bit_na(sa, da, width, s_offset, d_offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            sa += stride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            da += dstride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    case MLIB_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    case MLIB_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      width *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    case MLIB_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    case MLIB_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      width *= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    case MLIB_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
      width *= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
      return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
  if (!mlib_ImageIsNotOneDvector(src) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      !mlib_ImageIsNotOneDvector(dst)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
      size = height * width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
      if ((size & 0x3f) == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
          !mlib_ImageIsNotAligned64(src) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
          !mlib_ImageIsNotAligned64(dst)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
          mlib_v_ImageCopy_blk(sa, da, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
          return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      if (((size & 7) == 0) && !mlib_ImageIsNotAligned8(src) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
          !mlib_ImageIsNotAligned8(dst)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
          size >>= 3;                                /* in octlet */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
          mlib_v_ImageCopy_a1((mlib_d64 *)sa, (mlib_d64 *)da, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
      else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        mlib_ImageCopy_na(sa, da, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    stride = mlib_ImageGetStride(src);                /* in byte */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    dstride = mlib_ImageGetStride(dst);                /* in byte */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /* row loop */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    for (j = 0; j < height; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      mlib_ImageCopy_na(sa, da, width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
      sa += stride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
      da += dstride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
/***************************************************************/