jdk/src/share/native/sun/awt/medialib/mlib_ImageScanPoly.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) 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
 *  DESCRIPTION
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *    Calculates cliping boundary for Affine functions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "mlib_image.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "mlib_SysMath.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "mlib_ImageAffine.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/***************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
mlib_status mlib_AffineEdges(mlib_affine_param *param,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
                             const mlib_image  *dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
                             const mlib_image  *src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                             void              *buff_lcl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
                             mlib_s32          buff_size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
                             mlib_s32          kw,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                             mlib_s32          kh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                             mlib_s32          kw1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                             mlib_s32          kh1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                             mlib_edge         edge,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                             const mlib_d64    *mtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                             mlib_s32          shiftx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                             mlib_s32          shifty)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  mlib_u8 *buff = buff_lcl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  mlib_u8 **lineAddr = param->lineAddr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  mlib_s32 srcWidth, dstWidth, srcHeight, dstHeight, srcYStride, dstYStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  mlib_s32 *leftEdges, *rightEdges, *xStarts, *yStarts, bsize0, bsize1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  mlib_u8 *srcData, *dstData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  mlib_u8 *paddings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  void *warp_tbl = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  mlib_s32 yStart = 0, yFinish = -1, dX, dY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  mlib_d64 xClip, yClip, wClip, hClip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  mlib_d64 delta = 0.;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  mlib_d64 minX, minY, maxX, maxY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  mlib_d64 coords[4][2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  mlib_d64 a = mtx[0], b = mtx[1], tx = mtx[2], c = mtx[3], d = mtx[4], ty = mtx[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  mlib_d64 a2, b2, tx2, c2, d2, ty2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  mlib_d64 dx, dy, div;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  mlib_s32 sdx, sdy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  mlib_d64 dTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  mlib_d64 val0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
  mlib_s32 top, bot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  mlib_s32 topIdx, max_xsize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  mlib_s32 i, j, t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  srcData = mlib_ImageGetData(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  dstData = mlib_ImageGetData(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  srcWidth = mlib_ImageGetWidth(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  srcHeight = mlib_ImageGetHeight(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  dstWidth = mlib_ImageGetWidth(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  dstHeight = mlib_ImageGetHeight(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  srcYStride = mlib_ImageGetStride(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  dstYStride = mlib_ImageGetStride(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  paddings = mlib_ImageGetPaddings(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  if (srcWidth >= (1 << 15) || srcHeight >= (1 << 15)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  div = a * d - b * c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  if (div == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  bsize0 = (dstHeight * sizeof(mlib_s32) + 7) & ~7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  if (lineAddr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    bsize1 = ((srcHeight + 4 * kh) * sizeof(mlib_u8 *) + 7) & ~7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  param->buff_malloc = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  if ((4 * bsize0 + bsize1) > buff_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    buff = param->buff_malloc = mlib_malloc(4 * bsize0 + bsize1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    if (buff == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      return MLIB_FAILURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  leftEdges = (mlib_s32 *) (buff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  rightEdges = (mlib_s32 *) (buff += bsize0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
  xStarts = (mlib_s32 *) (buff += bsize0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
  yStarts = (mlib_s32 *) (buff += bsize0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
  if (lineAddr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    mlib_u8 *srcLinePtr = srcData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    lineAddr = (mlib_u8 **) (buff += bsize0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    for (i = 0; i < 2 * kh; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      lineAddr[i] = srcLinePtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    lineAddr += 2 * kh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    for (i = 0; i < srcHeight - 1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
      lineAddr[i] = srcLinePtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
      srcLinePtr += srcYStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    for (i = srcHeight - 1; i < srcHeight + 2 * kh; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      lineAddr[i] = srcLinePtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
  if ((mlib_s32) edge < 0) {                               /* process edges */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    minX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    minY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    maxX = srcWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    maxY = srcHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
  else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    if (kw > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      delta = -0.5;                                        /* for MLIB_NEAREST filter delta = 0. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    minX = (kw1 - delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    minY = (kh1 - delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    maxX = srcWidth - ((kw - 1) - (kw1 - delta));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    maxY = srcHeight - ((kh - 1) - (kh1 - delta));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    if (edge == MLIB_EDGE_SRC_PADDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
      if (minX < paddings[0])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        minX = paddings[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
      if (minY < paddings[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        minY = paddings[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
      if (maxX > (srcWidth - paddings[2]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        maxX = srcWidth - paddings[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
      if (maxY > (srcHeight - paddings[3]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        maxY = srcHeight - paddings[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  xClip = minX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
  yClip = minY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
  wClip = maxX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  hClip = maxY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *   STORE_PARAM(param, src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *   STORE_PARAM(param, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
  param->src = (void *)src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
  param->dst = (void *)dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  STORE_PARAM(param, lineAddr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
  STORE_PARAM(param, dstData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
  STORE_PARAM(param, srcYStride);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
  STORE_PARAM(param, dstYStride);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
  STORE_PARAM(param, leftEdges);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
  STORE_PARAM(param, rightEdges);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  STORE_PARAM(param, xStarts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
  STORE_PARAM(param, yStarts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
  STORE_PARAM(param, max_xsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
  STORE_PARAM(param, yStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
  STORE_PARAM(param, yFinish);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
  STORE_PARAM(param, warp_tbl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
  if ((xClip >= wClip) || (yClip >= hClip)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
  a2 = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
  b2 = -b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
  tx2 = (-d * tx + b * ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
  c2 = -c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  d2 = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
  ty2 = (c * tx - a * ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
  dx = a2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  dy = c2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
  tx -= 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
  ty -= 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
  coords[0][0] = xClip * a + yClip * b + tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
  coords[0][1] = xClip * c + yClip * d + ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
  coords[2][0] = wClip * a + hClip * b + tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
  coords[2][1] = wClip * c + hClip * d + ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
  if (div > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    coords[1][0] = wClip * a + yClip * b + tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    coords[1][1] = wClip * c + yClip * d + ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    coords[3][0] = xClip * a + hClip * b + tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    coords[3][1] = xClip * c + hClip * d + ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    coords[3][0] = wClip * a + yClip * b + tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    coords[3][1] = wClip * c + yClip * d + ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    coords[1][0] = xClip * a + hClip * b + tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    coords[1][1] = xClip * c + hClip * d + ty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
  topIdx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
  for (i = 1; i < 4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    if (coords[i][1] < coords[topIdx][1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
      topIdx = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
  dTop = coords[topIdx][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  val0 = dTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
  SAT32(top);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
  bot = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
  if (top >= dstHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  if (dTop >= 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    mlib_d64 xLeft, xRight, x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    mlib_s32 nextIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    if (dTop == top) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
      xLeft = coords[topIdx][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
      xRight = coords[topIdx][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
      nextIdx = (topIdx + 1) & 0x3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      if (dTop == coords[nextIdx][1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        x = coords[nextIdx][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        xLeft = (xLeft <= x) ? xLeft : x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        xRight = (xRight >= x) ? xRight : x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      nextIdx = (topIdx - 1) & 0x3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
      if (dTop == coords[nextIdx][1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        x = coords[nextIdx][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        xLeft = (xLeft <= x) ? xLeft : x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        xRight = (xRight >= x) ? xRight : x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      val0 = xLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
      SAT32(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
      leftEdges[top] = (t >= xLeft) ? t : ++t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      if (xLeft >= MLIB_S32_MAX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        leftEdges[top] = MLIB_S32_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      val0 = xRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      SAT32(rightEdges[top]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
      top++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    top = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
  for (i = 0; i < 2; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    mlib_d64 dY1 = coords[(topIdx - i) & 0x3][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    mlib_d64 dX1 = coords[(topIdx - i) & 0x3][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    mlib_d64 dY2 = coords[(topIdx - i - 1) & 0x3][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    mlib_d64 dX2 = coords[(topIdx - i - 1) & 0x3][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    mlib_d64 x = dX1, slope = (dX2 - dX1) / (dY2 - dY1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    mlib_s32 y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    mlib_s32 y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    if (dY1 == dY2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    if (dY1 < 0.0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      y1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      val0 = dY1 + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
      SAT32(y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    val0 = dY2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    SAT32(y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    if (y2 >= dstHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
      y2 = (mlib_s32) (dstHeight - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    x += slope * (y1 - dY1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    for (j = y1; j <= y2; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
      val0 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
      SAT32(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
      leftEdges[j] = (t >= x) ? t : ++t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
      if (x >= MLIB_S32_MAX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        leftEdges[j] = MLIB_S32_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
      x += slope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
  for (i = 0; i < 2; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    mlib_d64 dY1 = coords[(topIdx + i) & 0x3][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    mlib_d64 dX1 = coords[(topIdx + i) & 0x3][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    mlib_d64 dY2 = coords[(topIdx + i + 1) & 0x3][1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    mlib_d64 dX2 = coords[(topIdx + i + 1) & 0x3][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    mlib_d64 x = dX1, slope = (dX2 - dX1) / (dY2 - dY1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    mlib_s32 y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    mlib_s32 y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    if (dY1 == dY2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
      continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    if (dY1 < 0.0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
      y1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
      val0 = dY1 + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
      SAT32(y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    val0 = dY2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    SAT32(y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    if (y2 >= dstHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
      y2 = (mlib_s32) (dstHeight - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    x += slope * (y1 - dY1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    for (j = y1; j <= y2; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
      val0 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
      SAT32(rightEdges[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
      x += slope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    bot = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    mlib_d64 dxCl = xClip * div;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    mlib_d64 dyCl = yClip * div;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    mlib_d64 dwCl = wClip * div;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    mlib_d64 dhCl = hClip * div;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    mlib_s32 xCl = (mlib_s32) (xClip + delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    mlib_s32 yCl = (mlib_s32) (yClip + delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    mlib_s32 wCl = (mlib_s32) (wClip + delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    mlib_s32 hCl = (mlib_s32) (hClip + delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * mlib_s32 xCl = (mlib_s32)(xClip + delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * mlib_s32 yCl = (mlib_s32)(yClip + delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * mlib_s32 wCl = (mlib_s32)(wClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * mlib_s32 hCl = (mlib_s32)(hClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    if (edge == MLIB_EDGE_SRC_PADDED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
      xCl = kw1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
      yCl = kh1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
      wCl = (mlib_s32) (srcWidth - ((kw - 1) - kw1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
      hCl = (mlib_s32) (srcHeight - ((kh - 1) - kh1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    div = 1.0 / div;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    sdx = (mlib_s32) (a2 * div * (1 << shiftx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    sdy = (mlib_s32) (c2 * div * (1 << shifty));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    if (div > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
      for (i = top; i <= bot; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        mlib_s32 xLeft = leftEdges[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        mlib_s32 xRight = rightEdges[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        mlib_s32 xs, ys, x_e, y_e, x_s, y_s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        mlib_d64 dxs, dys, dxe, dye;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        mlib_d64 xl, ii, xr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        xLeft = (xLeft < 0) ? 0 : xLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        xRight = (xRight >= dstWidth) ? (mlib_s32) (dstWidth - 1) : xRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        xl = xLeft + 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        ii = i + 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        xr = xRight + 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        dxs = xl * a2 + ii * b2 + tx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        dys = xl * c2 + ii * d2 + ty2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if ((dxs < dxCl) || (dxs >= dwCl) || (dys < dyCl) || (dys >= dhCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
          dxs += dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
          dys += dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
          xLeft++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
          if ((dxs < dxCl) || (dxs >= dwCl) || (dys < dyCl) || (dys >= dhCl))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            xRight = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        dxe = xr * a2 + ii * b2 + tx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        dye = xr * c2 + ii * d2 + ty2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if ((dxe < dxCl) || (dxe >= dwCl) || (dye < dyCl) || (dye >= dhCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
          dxe -= dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
          dye -= dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
          xRight--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
          if ((dxe < dxCl) || (dxe >= dwCl) || (dye < dyCl) || (dye >= dhCl))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            xRight = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        xs = (mlib_s32) ((dxs * div + delta) * (1 << shiftx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        x_s = xs >> shiftx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        ys = (mlib_s32) ((dys * div + delta) * (1 << shifty));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        y_s = ys >> shifty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if (x_s < xCl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
          xs = (xCl << shiftx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        else if (x_s >= wCl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
          xs = ((wCl << shiftx) - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (y_s < yCl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
          ys = (yCl << shifty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        else if (y_s >= hCl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
          ys = ((hCl << shifty) - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (xRight >= xLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
          x_e = ((xRight - xLeft) * sdx + xs) >> shiftx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
          y_e = ((xRight - xLeft) * sdy + ys) >> shifty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
          if ((x_e < xCl) || (x_e >= wCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            if (sdx > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
              sdx -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
              sdx += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
          if ((y_e < yCl) || (y_e >= hCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if (sdy > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
              sdy -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
              sdy += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        leftEdges[i] = xLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        rightEdges[i] = xRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        xStarts[i] = xs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        yStarts[i] = ys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if ((xRight - xLeft + 1) > max_xsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
          max_xsize = (xRight - xLeft + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
#ifdef __SUNPRO_C
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
#pragma pipeloop(0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
#endif /* __SUNPRO_C */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
      for (i = top; i <= bot; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        mlib_s32 xLeft = leftEdges[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        mlib_s32 xRight = rightEdges[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        mlib_s32 xs, ys, x_e, y_e, x_s, y_s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        mlib_d64 dxs, dys, dxe, dye;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        mlib_d64 xl, ii, xr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        xLeft = (xLeft < 0) ? 0 : xLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        xRight = (xRight >= dstWidth) ? (mlib_s32) (dstWidth - 1) : xRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        xl = xLeft + 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        ii = i + 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        xr = xRight + 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        dxs = xl * a2 + ii * b2 + tx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        dys = xl * c2 + ii * d2 + ty2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if ((dxs > dxCl) || (dxs <= dwCl) || (dys > dyCl) || (dys <= dhCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
          dxs += dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
          dys += dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
          xLeft++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
          if ((dxs > dxCl) || (dxs <= dwCl) || (dys > dyCl) || (dys <= dhCl))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            xRight = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        dxe = xr * a2 + ii * b2 + tx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        dye = xr * c2 + ii * d2 + ty2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        if ((dxe > dxCl) || (dxe <= dwCl) || (dye > dyCl) || (dye <= dhCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
          dxe -= dx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
          dye -= dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
          xRight--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
          if ((dxe > dxCl) || (dxe <= dwCl) || (dye > dyCl) || (dye <= dhCl))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            xRight = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        xs = (mlib_s32) ((dxs * div + delta) * (1 << shiftx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        x_s = xs >> shiftx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        if (x_s < xCl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
          xs = (xCl << shiftx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        else if (x_s >= wCl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
          xs = ((wCl << shiftx) - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        ys = (mlib_s32) ((dys * div + delta) * (1 << shifty));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        y_s = ys >> shifty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        if (y_s < yCl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
          ys = (yCl << shifty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        else if (y_s >= hCl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
          ys = ((hCl << shifty) - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        if (xRight >= xLeft) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
          x_e = ((xRight - xLeft) * sdx + xs) >> shiftx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
          y_e = ((xRight - xLeft) * sdy + ys) >> shifty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
          if ((x_e < xCl) || (x_e >= wCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            if (sdx > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
              sdx -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
              sdx += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
          if ((y_e < yCl) || (y_e >= hCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            if (sdy > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
              sdy -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
              sdy += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        leftEdges[i] = xLeft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        rightEdges[i] = xRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        xStarts[i] = xs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        yStarts[i] = ys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if ((xRight - xLeft + 1) > max_xsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
          max_xsize = (xRight - xLeft + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
  while (leftEdges[top] > rightEdges[top] && top <= bot)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    top++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
  if (top < bot)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    while (leftEdges[bot] > rightEdges[bot])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
      bot--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
  yStart = top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
  yFinish = bot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
  dX = sdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
  dY = sdy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
  dstData += (yStart - 1) * dstYStride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
  STORE_PARAM(param, dstData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
  STORE_PARAM(param, yStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
  STORE_PARAM(param, yFinish);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
  STORE_PARAM(param, max_xsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
  STORE_PARAM(param, dX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
  STORE_PARAM(param, dY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
  return MLIB_SUCCESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
/***************************************************************/