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