Source Code Cross Referenced for ScaleBicubicOpImage.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » com » sun » media » jai » opimage » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » Java Advanced Imaging » com.sun.media.jai.opimage 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * $RCSfile: ScaleBicubicOpImage.java,v $
0003:         *
0004:         * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * Use is subject to license terms.
0007:         *
0008:         * $Revision: 1.1 $
0009:         * $Date: 2005/02/11 04:56:42 $
0010:         * $State: Exp $
0011:         */
0012:        package com.sun.media.jai.opimage;
0013:
0014:        import java.awt.Rectangle;
0015:        import java.awt.image.DataBuffer;
0016:        import java.awt.image.Raster;
0017:        import java.awt.image.RenderedImage;
0018:        import java.awt.image.WritableRaster;
0019:        import java.awt.image.renderable.ParameterBlock;
0020:        import javax.media.jai.BorderExtender;
0021:        import javax.media.jai.ImageLayout;
0022:        import javax.media.jai.Interpolation;
0023:        import javax.media.jai.InterpolationBicubic;
0024:        import javax.media.jai.InterpolationBicubic2;
0025:        import javax.media.jai.InterpolationTable;
0026:        import javax.media.jai.OpImage;
0027:        import javax.media.jai.PlanarImage;
0028:        import javax.media.jai.RasterAccessor;
0029:        import javax.media.jai.RasterFormatTag;
0030:        import javax.media.jai.ScaleOpImage;
0031:        import java.util.Map;
0032:        import com.sun.media.jai.util.Rational;
0033:
0034:        // import com.sun.media.jai.test.OpImageTester;
0035:
0036:        /**
0037:         * An <code>OpImage</code> that performs bicubic interpolation scaling.
0038:         *
0039:         */
0040:        final class ScaleBicubicOpImage extends ScaleOpImage {
0041:
0042:            /* The number of subsampleBits */
0043:            private int subsampleBits;
0044:
0045:            /* 2 ^ subsampleBits */
0046:            private int one;
0047:
0048:            /** The horizontal coefficient data in fixed-point format. */
0049:            private int[] tableDataHi = null;
0050:
0051:            /** The vertical coefficient data in fixed-point format. */
0052:            private int[] tableDataVi = null;
0053:
0054:            /** The horizontal coefficient data in floating-point format. */
0055:            private float[] tableDataHf = null;
0056:
0057:            /** The vertical coefficient data in floating-point format. */
0058:            private float[] tableDataVf = null;
0059:
0060:            /** The horizontal coefficient data in double format. */
0061:            private double[] tableDataHd = null;
0062:
0063:            /** The vertical coefficient data in double format. */
0064:            private double[] tableDataVd = null;
0065:
0066:            /** Number of fractional bits used to described filter coefficients. */
0067:            private int precisionBits;
0068:
0069:            /** The number 1/2 with precisionBits of fractional precision. */
0070:            private int round;
0071:
0072:            private Rational half = new Rational(1, 2);
0073:
0074:            // The InterpolationTable superclass.
0075:            InterpolationTable interpTable;
0076:
0077:            long invScaleYInt, invScaleYFrac;
0078:            long invScaleXInt, invScaleXFrac;
0079:
0080:            /**
0081:             * Constructs a ScaleBicubicOpImage from a RenderedImage source,
0082:             * 
0083:             * @param source a RenderedImage.
0084:             * @param extender a BorderExtender, or null.
0085:             * @param layout an ImageLayout optionally containing the tile grid layout,
0086:             *        SampleModel, and ColorModel, or null.
0087:             * @param xScale scale factor along x axis.
0088:             * @param yScale scale factor along y axis.
0089:             * @param xTrans translation factor along x axis.
0090:             * @param yTrans translation factor along y axis.
0091:             * @param interp a Interpolation object to use for resampling.
0092:             */
0093:            public ScaleBicubicOpImage(RenderedImage source,
0094:                    BorderExtender extender, Map config, ImageLayout layout,
0095:                    float xScale, float yScale, float xTrans, float yTrans,
0096:                    Interpolation interp) {
0097:                super (source, layout, config, true, extender, interp, xScale,
0098:                        yScale, xTrans, yTrans);
0099:
0100:                subsampleBits = interp.getSubsampleBitsH();
0101:                interpTable = (InterpolationTable) interp;
0102:
0103:                // Number of subsample positions
0104:                one = 1 << subsampleBits;
0105:                precisionBits = interpTable.getPrecisionBits();
0106:                if (precisionBits > 0) {
0107:                    round = 1 << (precisionBits - 1);
0108:                }
0109:
0110:                if (invScaleYRational.num > invScaleYRational.denom) {
0111:                    invScaleYInt = invScaleYRational.num
0112:                            / invScaleYRational.denom;
0113:                    invScaleYFrac = invScaleYRational.num
0114:                            % invScaleYRational.denom;
0115:                } else {
0116:                    invScaleYInt = 0;
0117:                    invScaleYFrac = invScaleYRational.num;
0118:                }
0119:
0120:                if (invScaleXRational.num > invScaleXRational.denom) {
0121:                    invScaleXInt = invScaleXRational.num
0122:                            / invScaleXRational.denom;
0123:                    invScaleXFrac = invScaleXRational.num
0124:                            % invScaleXRational.denom;
0125:                } else {
0126:                    invScaleXInt = 0;
0127:                    invScaleXFrac = invScaleXRational.num;
0128:                }
0129:            }
0130:
0131:            /**
0132:             * Performs a scale operation on a specified rectangle. The sources are
0133:             * cobbled.
0134:             *
0135:             * @param sources  an array of source Rasters, guaranteed to provide all
0136:             *                 necessary source data for computing the output.
0137:             * @param dest     a WritableRaster containing the area to be computed.
0138:             * @param destRect the rectangle within dest to be processed.
0139:             */
0140:            protected void computeRect(Raster[] sources, WritableRaster dest,
0141:                    Rectangle destRect) {
0142:                // Retrieve format tags.
0143:                RasterFormatTag[] formatTags = getFormatTags();
0144:
0145:                Raster source = sources[0];
0146:                // Get the source rectangle
0147:                Rectangle srcRect = source.getBounds();
0148:
0149:                int srcRectX = srcRect.x;
0150:                int srcRectY = srcRect.y;
0151:
0152:                RasterAccessor srcAccessor = new RasterAccessor(source,
0153:                        srcRect, formatTags[0], getSource(0).getColorModel());
0154:
0155:                RasterAccessor dstAccessor = new RasterAccessor(dest, destRect,
0156:                        formatTags[1], getColorModel());
0157:
0158:                // Loop variables based on the destination rectangle to be calculated.
0159:                int dx = destRect.x;
0160:                int dy = destRect.y;
0161:                int dwidth = destRect.width;
0162:                int dheight = destRect.height;
0163:                int srcPixelStride = srcAccessor.getPixelStride();
0164:                int srcScanlineStride = srcAccessor.getScanlineStride();
0165:
0166:                int[] ypos = new int[dheight];
0167:                int[] xpos = new int[dwidth];
0168:
0169:                // Precalculate the y positions and store them in an array.
0170:                int[] yfracvalues = new int[dheight];
0171:                // Precalculate the x positions and store them in an array.
0172:                int[] xfracvalues = new int[dwidth];
0173:
0174:                long syNum = dy, syDenom = 1;
0175:
0176:                // Subtract the X translation factor sy -= transY
0177:                syNum = syNum * transYRationalDenom - transYRationalNum
0178:                        * syDenom;
0179:                syDenom *= transYRationalDenom;
0180:
0181:                // Add 0.5
0182:                syNum = 2 * syNum + syDenom;
0183:                syDenom *= 2;
0184:
0185:                // Multply by invScaleX
0186:                syNum *= invScaleYRationalNum;
0187:                syDenom *= invScaleYRationalDenom;
0188:
0189:                // Subtract 0.5
0190:                syNum = 2 * syNum - syDenom;
0191:                syDenom *= 2;
0192:
0193:                // Separate the x source coordinate into integer and fractional part
0194:                int srcYInt = Rational.floor(syNum, syDenom);
0195:                long srcYFrac = syNum % syDenom;
0196:                if (srcYInt < 0) {
0197:                    srcYFrac = syDenom + srcYFrac;
0198:                }
0199:
0200:                // Normalize - Get a common denominator for the fracs of 
0201:                // src and invScaleY
0202:                long commonYDenom = syDenom * invScaleYRationalDenom;
0203:                srcYFrac *= invScaleYRationalDenom;
0204:                long newInvScaleYFrac = invScaleYFrac * syDenom;
0205:
0206:                long sxNum = dx, sxDenom = 1;
0207:
0208:                // Subtract the X translation factor sx -= transX
0209:                sxNum = sxNum * transXRationalDenom - transXRationalNum
0210:                        * sxDenom;
0211:                sxDenom *= transXRationalDenom;
0212:
0213:                // Add 0.5
0214:                sxNum = 2 * sxNum + sxDenom;
0215:                sxDenom *= 2;
0216:
0217:                // Multply by invScaleX
0218:                sxNum *= invScaleXRationalNum;
0219:                sxDenom *= invScaleXRationalDenom;
0220:
0221:                // Subtract 0.5
0222:                sxNum = 2 * sxNum - sxDenom;
0223:                sxDenom *= 2;
0224:
0225:                // Separate the x source coordinate into integer and fractional part
0226:                // int part is floor(sx), frac part is sx - floor(sx)
0227:                int srcXInt = Rational.floor(sxNum, sxDenom);
0228:                long srcXFrac = sxNum % sxDenom;
0229:                if (srcXInt < 0) {
0230:                    srcXFrac = sxDenom + srcXFrac;
0231:                }
0232:
0233:                // Normalize - Get a common denominator for the fracs of 
0234:                // src and invScaleX
0235:                long commonXDenom = sxDenom * invScaleXRationalDenom;
0236:                srcXFrac *= invScaleXRationalDenom;
0237:                long newInvScaleXFrac = invScaleXFrac * sxDenom;
0238:
0239:                for (int i = 0; i < dwidth; i++) {
0240:                    xpos[i] = (srcXInt - srcRectX) * srcPixelStride;
0241:                    xfracvalues[i] = (int) (((float) srcXFrac / (float) commonXDenom) * one);
0242:
0243:                    // Move onto the next source pixel.
0244:
0245:                    // Add the integral part of invScaleX to the integral part
0246:                    // of srcX
0247:                    srcXInt += invScaleXInt;
0248:
0249:                    // Add the fractional part of invScaleX to the fractional part
0250:                    // of srcX
0251:                    srcXFrac += newInvScaleXFrac;
0252:
0253:                    // If the fractional part is now greater than equal to the
0254:                    // denominator, divide so as to reduce the numerator to be less
0255:                    // than the denominator and add the overflow to the integral part.
0256:                    if (srcXFrac >= commonXDenom) {
0257:                        srcXInt += 1;
0258:                        srcXFrac -= commonXDenom;
0259:                    }
0260:                }
0261:
0262:                for (int i = 0; i < dheight; i++) {
0263:
0264:                    // Calculate the source position in the source data array.
0265:                    ypos[i] = (srcYInt - srcRectY) * srcScanlineStride;
0266:
0267:                    // Calculate the yfrac value
0268:                    yfracvalues[i] = (int) (((float) srcYFrac / (float) commonYDenom) * one);
0269:
0270:                    // Move onto the next source pixel.
0271:
0272:                    // Add the integral part of invScaleY to the integral part
0273:                    // of srcY
0274:                    srcYInt += invScaleYInt;
0275:
0276:                    // Add the fractional part of invScaleY to the fractional part
0277:                    // of srcY
0278:                    srcYFrac += newInvScaleYFrac;
0279:
0280:                    // If the fractional part is now greater than equal to the 
0281:                    // denominator, divide so as to reduce the numerator to be less
0282:                    // than the denominator and add the overflow to the integral part.
0283:                    if (srcYFrac >= commonYDenom) {
0284:                        srcYInt += 1;
0285:                        srcYFrac -= commonYDenom;
0286:                    }
0287:                }
0288:
0289:                switch (dstAccessor.getDataType()) {
0290:
0291:                case DataBuffer.TYPE_BYTE:
0292:                    initTableDataI();
0293:                    byteLoop(srcAccessor, destRect, dstAccessor, xpos, ypos,
0294:                            xfracvalues, yfracvalues);
0295:                    break;
0296:
0297:                case DataBuffer.TYPE_SHORT:
0298:                    initTableDataI();
0299:                    shortLoop(srcAccessor, destRect, dstAccessor, xpos, ypos,
0300:                            xfracvalues, yfracvalues);
0301:                    break;
0302:
0303:                case DataBuffer.TYPE_USHORT:
0304:                    initTableDataI();
0305:                    ushortLoop(srcAccessor, destRect, dstAccessor, xpos, ypos,
0306:                            xfracvalues, yfracvalues);
0307:                    break;
0308:
0309:                case DataBuffer.TYPE_INT:
0310:                    initTableDataI();
0311:                    intLoop(srcAccessor, destRect, dstAccessor, xpos, ypos,
0312:                            xfracvalues, yfracvalues);
0313:                    break;
0314:
0315:                case DataBuffer.TYPE_FLOAT:
0316:                    initTableDataF();
0317:                    floatLoop(srcAccessor, destRect, dstAccessor, xpos, ypos,
0318:                            xfracvalues, yfracvalues);
0319:                    break;
0320:
0321:                case DataBuffer.TYPE_DOUBLE:
0322:                    initTableDataD();
0323:                    doubleLoop(srcAccessor, destRect, dstAccessor, xpos, ypos,
0324:                            xfracvalues, yfracvalues);
0325:                    break;
0326:
0327:                default:
0328:                    throw new RuntimeException(JaiI18N
0329:                            .getString("OrderedDitherOpImage0"));
0330:                }
0331:
0332:                // If the RasterAccessor object set up a temporary buffer for the 
0333:                // op to write to, tell the RasterAccessor to write that data
0334:                // to the raster no that we're done with it.
0335:                if (dstAccessor.isDataCopy()) {
0336:                    dstAccessor.clampDataArrays();
0337:                    dstAccessor.copyDataToRaster();
0338:                }
0339:            }
0340:
0341:            private void byteLoop(RasterAccessor src, Rectangle destRect,
0342:                    RasterAccessor dst, int xpos[], int ypos[],
0343:                    int xfracvalues[], int yfracvalues[]) {
0344:
0345:                int srcPixelStride = src.getPixelStride();
0346:                int srcScanlineStride = src.getScanlineStride();
0347:
0348:                int dwidth = destRect.width;
0349:                int dheight = destRect.height;
0350:                int dnumBands = dst.getNumBands();
0351:                byte dstDataArrays[][] = dst.getByteDataArrays();
0352:                int dstBandOffsets[] = dst.getBandOffsets();
0353:                int dstPixelStride = dst.getPixelStride();
0354:                int dstScanlineStride = dst.getScanlineStride();
0355:
0356:                byte srcDataArrays[][] = src.getByteDataArrays();
0357:                int bandOffsets[] = src.getBandOffsets();
0358:
0359:                int posy, posylow, posyhigh, posyhigh2;
0360:                int posx, posxlow, posxhigh, posxhigh2;
0361:                int xfrac, yfrac;
0362:                int s__, s_0, s_1, s_2;
0363:                int s0_, s00, s01, s02;
0364:                int s1_, s10, s11, s12;
0365:                int s2_, s20, s21, s22;
0366:                int s, dstOffset = 0;
0367:
0368:                // Putting band loop outside
0369:                for (int k = 0; k < dnumBands; k++) {
0370:                    byte dstData[] = dstDataArrays[k];
0371:                    byte srcData[] = srcDataArrays[k];
0372:                    int dstScanlineOffset = dstBandOffsets[k];
0373:                    int bandOffset = bandOffsets[k];
0374:
0375:                    for (int j = 0; j < dheight; j++) {
0376:                        int dstPixelOffset = dstScanlineOffset;
0377:                        yfrac = yfracvalues[j];
0378:                        posy = ypos[j] + bandOffset;
0379:                        posylow = posy - srcScanlineStride;
0380:                        posyhigh = posy + srcScanlineStride;
0381:                        posyhigh2 = posyhigh + srcScanlineStride;
0382:                        for (int i = 0; i < dwidth; i++) {
0383:                            xfrac = xfracvalues[i];
0384:                            posx = xpos[i];
0385:                            posxlow = posx - srcPixelStride;
0386:                            posxhigh = posx + srcPixelStride;
0387:                            posxhigh2 = posxhigh + srcPixelStride;
0388:
0389:                            // Get the sixteen surrounding pixel values
0390:                            s__ = srcData[posxlow + posylow] & 0xff;
0391:                            s_0 = srcData[posx + posylow] & 0xff;
0392:                            s_1 = srcData[posxhigh + posylow] & 0xff;
0393:                            s_2 = srcData[posxhigh2 + posylow] & 0xff;
0394:
0395:                            s0_ = srcData[posxlow + posy] & 0xff;
0396:                            s00 = srcData[posx + posy] & 0xff;
0397:                            s01 = srcData[posxhigh + posy] & 0xff;
0398:                            s02 = srcData[posxhigh2 + posy] & 0xff;
0399:
0400:                            s1_ = srcData[posxlow + posyhigh] & 0xff;
0401:                            s10 = srcData[posx + posyhigh] & 0xff;
0402:                            s11 = srcData[posxhigh + posyhigh] & 0xff;
0403:                            s12 = srcData[posxhigh2 + posyhigh] & 0xff;
0404:
0405:                            s2_ = srcData[posxlow + posyhigh2] & 0xff;
0406:                            s20 = srcData[posx + posyhigh2] & 0xff;
0407:                            s21 = srcData[posxhigh + posyhigh2] & 0xff;
0408:                            s22 = srcData[posxhigh2 + posyhigh2] & 0xff;
0409:
0410:                            // Interpolate in X
0411:                            int offsetX = 4 * xfrac;
0412:                            int offsetX1 = offsetX + 1;
0413:                            int offsetX2 = offsetX + 2;
0414:                            int offsetX3 = offsetX + 3;
0415:
0416:                            long sum_ = (long) tableDataHi[offsetX] * s__;
0417:                            sum_ += (long) tableDataHi[offsetX1] * s_0;
0418:                            sum_ += (long) tableDataHi[offsetX2] * s_1;
0419:                            sum_ += (long) tableDataHi[offsetX3] * s_2;
0420:
0421:                            long sum0 = (long) tableDataHi[offsetX] * s0_;
0422:                            sum0 += (long) tableDataHi[offsetX1] * s00;
0423:                            sum0 += (long) tableDataHi[offsetX2] * s01;
0424:                            sum0 += (long) tableDataHi[offsetX3] * s02;
0425:
0426:                            long sum1 = (long) tableDataHi[offsetX] * s1_;
0427:                            sum1 += (long) tableDataHi[offsetX1] * s10;
0428:                            sum1 += (long) tableDataHi[offsetX2] * s11;
0429:                            sum1 += (long) tableDataHi[offsetX3] * s12;
0430:
0431:                            long sum2 = (long) tableDataHi[offsetX] * s2_;
0432:                            sum2 += (long) tableDataHi[offsetX1] * s20;
0433:                            sum2 += (long) tableDataHi[offsetX2] * s21;
0434:                            sum2 += (long) tableDataHi[offsetX3] * s22;
0435:
0436:                            // Intermediate rounding
0437:                            sum_ = (sum_ + round) >> precisionBits;
0438:                            sum0 = (sum0 + round) >> precisionBits;
0439:                            sum1 = (sum1 + round) >> precisionBits;
0440:                            sum2 = (sum2 + round) >> precisionBits;
0441:
0442:                            // Interpolate in Y
0443:                            int offsetY = 4 * yfrac;
0444:                            long sum = (long) tableDataVi[offsetY] * sum_;
0445:                            sum += (long) tableDataVi[offsetY + 1] * sum0;
0446:                            sum += (long) tableDataVi[offsetY + 2] * sum1;
0447:                            sum += (long) tableDataVi[offsetY + 3] * sum2;
0448:
0449:                            s = (int) ((sum + round) >> precisionBits);
0450:
0451:                            // clamp the value to byte range
0452:                            if (s > 255) {
0453:                                s = 255;
0454:                            } else if (s < 0) {
0455:                                s = 0;
0456:                            }
0457:
0458:                            dstData[dstPixelOffset] = (byte) (s & 0xff);
0459:                            dstPixelOffset += dstPixelStride;
0460:                        }
0461:                        dstScanlineOffset += dstScanlineStride;
0462:                    }
0463:                }
0464:            }
0465:
0466:            private void shortLoop(RasterAccessor src, Rectangle destRect,
0467:                    RasterAccessor dst, int xpos[], int ypos[],
0468:                    int xfracvalues[], int yfracvalues[]) {
0469:
0470:                int srcPixelStride = src.getPixelStride();
0471:                int srcScanlineStride = src.getScanlineStride();
0472:
0473:                int dwidth = destRect.width;
0474:                int dheight = destRect.height;
0475:                int dnumBands = dst.getNumBands();
0476:                short dstDataArrays[][] = dst.getShortDataArrays();
0477:                int dstBandOffsets[] = dst.getBandOffsets();
0478:                int dstPixelStride = dst.getPixelStride();
0479:                int dstScanlineStride = dst.getScanlineStride();
0480:
0481:                short srcDataArrays[][] = src.getShortDataArrays();
0482:                int bandOffsets[] = src.getBandOffsets();
0483:
0484:                int dstOffset = 0;
0485:
0486:                int posy, posylow, posyhigh, posyhigh2;
0487:                int posx, posxlow, posxhigh, posxhigh2;
0488:                int xfrac, yfrac;
0489:                int s__, s_0, s_1, s_2;
0490:                int s0_, s00, s01, s02;
0491:                int s1_, s10, s11, s12;
0492:                int s2_, s20, s21, s22;
0493:                int s;
0494:
0495:                // Putting band loop outside
0496:                for (int k = 0; k < dnumBands; k++) {
0497:                    short dstData[] = dstDataArrays[k];
0498:                    short srcData[] = srcDataArrays[k];
0499:                    int dstScanlineOffset = dstBandOffsets[k];
0500:                    int bandOffset = bandOffsets[k];
0501:
0502:                    for (int j = 0; j < dheight; j++) {
0503:                        int dstPixelOffset = dstScanlineOffset;
0504:                        yfrac = yfracvalues[j];
0505:                        posy = ypos[j] + bandOffset;
0506:                        posylow = posy - srcScanlineStride;
0507:                        posyhigh = posy + srcScanlineStride;
0508:                        posyhigh2 = posyhigh + srcScanlineStride;
0509:                        for (int i = 0; i < dwidth; i++) {
0510:                            xfrac = xfracvalues[i];
0511:                            posx = xpos[i];
0512:                            posxlow = posx - srcPixelStride;
0513:                            posxhigh = posx + srcPixelStride;
0514:                            posxhigh2 = posxhigh + srcPixelStride;
0515:
0516:                            // Get the sixteen surrounding pixel values
0517:                            s__ = srcData[posxlow + posylow];
0518:                            s_0 = srcData[posx + posylow];
0519:                            s_1 = srcData[posxhigh + posylow];
0520:                            s_2 = srcData[posxhigh2 + posylow];
0521:
0522:                            s0_ = srcData[posxlow + posy];
0523:                            s00 = srcData[posx + posy];
0524:                            s01 = srcData[posxhigh + posy];
0525:                            s02 = srcData[posxhigh2 + posy];
0526:
0527:                            s1_ = srcData[posxlow + posyhigh];
0528:                            s10 = srcData[posx + posyhigh];
0529:                            s11 = srcData[posxhigh + posyhigh];
0530:                            s12 = srcData[posxhigh2 + posyhigh];
0531:
0532:                            s2_ = srcData[posxlow + posyhigh2];
0533:                            s20 = srcData[posx + posyhigh2];
0534:                            s21 = srcData[posxhigh + posyhigh2];
0535:                            s22 = srcData[posxhigh2 + posyhigh2];
0536:
0537:                            // Interpolate in X
0538:                            int offsetX = 4 * xfrac;
0539:                            int offsetX1 = offsetX + 1;
0540:                            int offsetX2 = offsetX + 2;
0541:                            int offsetX3 = offsetX + 3;
0542:
0543:                            long sum_ = (long) tableDataHi[offsetX] * s__;
0544:                            sum_ += (long) tableDataHi[offsetX1] * s_0;
0545:                            sum_ += (long) tableDataHi[offsetX2] * s_1;
0546:                            sum_ += (long) tableDataHi[offsetX3] * s_2;
0547:
0548:                            long sum0 = (long) tableDataHi[offsetX] * s0_;
0549:                            sum0 += (long) tableDataHi[offsetX1] * s00;
0550:                            sum0 += (long) tableDataHi[offsetX2] * s01;
0551:                            sum0 += (long) tableDataHi[offsetX3] * s02;
0552:
0553:                            long sum1 = (long) tableDataHi[offsetX] * s1_;
0554:                            sum1 += (long) tableDataHi[offsetX1] * s10;
0555:                            sum1 += (long) tableDataHi[offsetX2] * s11;
0556:                            sum1 += (long) tableDataHi[offsetX3] * s12;
0557:
0558:                            long sum2 = (long) tableDataHi[offsetX] * s2_;
0559:                            sum2 += (long) tableDataHi[offsetX1] * s20;
0560:                            sum2 += (long) tableDataHi[offsetX2] * s21;
0561:                            sum2 += (long) tableDataHi[offsetX3] * s22;
0562:
0563:                            // Intermediate rounding
0564:                            sum_ = (sum_ + round) >> precisionBits;
0565:                            sum0 = (sum0 + round) >> precisionBits;
0566:                            sum1 = (sum1 + round) >> precisionBits;
0567:                            sum2 = (sum2 + round) >> precisionBits;
0568:
0569:                            // Interpolate in Y
0570:                            int offsetY = 4 * yfrac;
0571:                            long sum = (long) tableDataVi[offsetY] * sum_;
0572:                            sum += (long) tableDataVi[offsetY + 1] * sum0;
0573:                            sum += (long) tableDataVi[offsetY + 2] * sum1;
0574:                            sum += (long) tableDataVi[offsetY + 3] * sum2;
0575:
0576:                            s = (int) ((sum + round) >> precisionBits);
0577:
0578:                            // clamp the value to short range
0579:                            if (s > Short.MAX_VALUE) {
0580:                                s = Short.MAX_VALUE;
0581:                            } else if (s < Short.MIN_VALUE) {
0582:                                s = Short.MIN_VALUE;
0583:                            }
0584:
0585:                            dstData[dstPixelOffset] = (short) s;
0586:                            dstPixelOffset += dstPixelStride;
0587:                        }
0588:                        dstScanlineOffset += dstScanlineStride;
0589:                    }
0590:                }
0591:            }
0592:
0593:            private void ushortLoop(RasterAccessor src, Rectangle destRect,
0594:                    RasterAccessor dst, int xpos[], int ypos[],
0595:                    int xfracvalues[], int yfracvalues[]) {
0596:
0597:                int srcPixelStride = src.getPixelStride();
0598:                int srcScanlineStride = src.getScanlineStride();
0599:
0600:                int dwidth = destRect.width;
0601:                int dheight = destRect.height;
0602:                int dnumBands = dst.getNumBands();
0603:                short dstDataArrays[][] = dst.getShortDataArrays();
0604:                int dstBandOffsets[] = dst.getBandOffsets();
0605:                int dstPixelStride = dst.getPixelStride();
0606:                int dstScanlineStride = dst.getScanlineStride();
0607:
0608:                short srcDataArrays[][] = src.getShortDataArrays();
0609:                int bandOffsets[] = src.getBandOffsets();
0610:
0611:                int dstOffset = 0;
0612:
0613:                int posy, posylow, posyhigh, posyhigh2;
0614:                int posx, posxlow, posxhigh, posxhigh2;
0615:                int xfrac, yfrac;
0616:                int s__, s_0, s_1, s_2;
0617:                int s0_, s00, s01, s02;
0618:                int s1_, s10, s11, s12;
0619:                int s2_, s20, s21, s22;
0620:                int s;
0621:
0622:                // Putting band loop outside
0623:                for (int k = 0; k < dnumBands; k++) {
0624:                    short dstData[] = dstDataArrays[k];
0625:                    short srcData[] = srcDataArrays[k];
0626:                    int dstScanlineOffset = dstBandOffsets[k];
0627:                    int bandOffset = bandOffsets[k];
0628:
0629:                    for (int j = 0; j < dheight; j++) {
0630:                        int dstPixelOffset = dstScanlineOffset;
0631:                        yfrac = yfracvalues[j];
0632:                        posy = ypos[j] + bandOffset;
0633:                        posylow = posy - srcScanlineStride;
0634:                        posyhigh = posy + srcScanlineStride;
0635:                        posyhigh2 = posyhigh + srcScanlineStride;
0636:                        for (int i = 0; i < dwidth; i++) {
0637:                            xfrac = xfracvalues[i];
0638:                            posx = xpos[i];
0639:                            posxlow = posx - srcPixelStride;
0640:                            posxhigh = posx + srcPixelStride;
0641:                            posxhigh2 = posxhigh + srcPixelStride;
0642:
0643:                            // Get the sixteen surrounding pixel values
0644:                            s__ = srcData[posxlow + posylow] & 0xffff;
0645:                            s_0 = srcData[posx + posylow] & 0xffff;
0646:                            s_1 = srcData[posxhigh + posylow] & 0xffff;
0647:                            s_2 = srcData[posxhigh2 + posylow] & 0xffff;
0648:
0649:                            s0_ = srcData[posxlow + posy] & 0xffff;
0650:                            s00 = srcData[posx + posy] & 0xffff;
0651:                            s01 = srcData[posxhigh + posy] & 0xffff;
0652:                            s02 = srcData[posxhigh2 + posy] & 0xffff;
0653:
0654:                            s1_ = srcData[posxlow + posyhigh] & 0xffff;
0655:                            s10 = srcData[posx + posyhigh] & 0xffff;
0656:                            s11 = srcData[posxhigh + posyhigh] & 0xffff;
0657:                            s12 = srcData[posxhigh2 + posyhigh] & 0xffff;
0658:
0659:                            s2_ = srcData[posxlow + posyhigh2] & 0xffff;
0660:                            s20 = srcData[posx + posyhigh2] & 0xffff;
0661:                            s21 = srcData[posxhigh + posyhigh2] & 0xffff;
0662:                            s22 = srcData[posxhigh2 + posyhigh2] & 0xffff;
0663:
0664:                            // Interpolate in X
0665:                            int offsetX = 4 * xfrac;
0666:                            int offsetX1 = offsetX + 1;
0667:                            int offsetX2 = offsetX + 2;
0668:                            int offsetX3 = offsetX + 3;
0669:
0670:                            long sum_ = (long) tableDataHi[offsetX] * s__;
0671:                            sum_ += (long) tableDataHi[offsetX1] * s_0;
0672:                            sum_ += (long) tableDataHi[offsetX2] * s_1;
0673:                            sum_ += (long) tableDataHi[offsetX3] * s_2;
0674:
0675:                            long sum0 = (long) tableDataHi[offsetX] * s0_;
0676:                            sum0 += (long) tableDataHi[offsetX1] * s00;
0677:                            sum0 += (long) tableDataHi[offsetX2] * s01;
0678:                            sum0 += (long) tableDataHi[offsetX3] * s02;
0679:
0680:                            long sum1 = (long) tableDataHi[offsetX] * s1_;
0681:                            sum1 += (long) tableDataHi[offsetX1] * s10;
0682:                            sum1 += (long) tableDataHi[offsetX2] * s11;
0683:                            sum1 += (long) tableDataHi[offsetX3] * s12;
0684:
0685:                            long sum2 = (long) tableDataHi[offsetX] * s2_;
0686:                            sum2 += (long) tableDataHi[offsetX1] * s20;
0687:                            sum2 += (long) tableDataHi[offsetX2] * s21;
0688:                            sum2 += (long) tableDataHi[offsetX3] * s22;
0689:
0690:                            // Intermediate rounding
0691:                            sum_ = (sum_ + round) >> precisionBits;
0692:                            sum0 = (sum0 + round) >> precisionBits;
0693:                            sum1 = (sum1 + round) >> precisionBits;
0694:                            sum2 = (sum2 + round) >> precisionBits;
0695:
0696:                            // Interpolate in Y
0697:                            int offsetY = 4 * yfrac;
0698:                            long sum = (long) tableDataVi[offsetY] * sum_;
0699:                            sum += (long) tableDataVi[offsetY + 1] * sum0;
0700:                            sum += (long) tableDataVi[offsetY + 2] * sum1;
0701:                            sum += (long) tableDataVi[offsetY + 3] * sum2;
0702:
0703:                            s = (int) ((sum + round) >> precisionBits);
0704:
0705:                            // clamp the value to ushort range
0706:                            if (s > 65536) {
0707:                                s = 65536;
0708:                            } else if (s < 0) {
0709:                                s = 0;
0710:                            }
0711:
0712:                            dstData[dstPixelOffset] = (short) (s & 0xffff);
0713:                            dstPixelOffset += dstPixelStride;
0714:                        }
0715:                        dstScanlineOffset += dstScanlineStride;
0716:                    }
0717:                }
0718:            }
0719:
0720:            // identical to byteLoops, except datatypes have changed.  clumsy,
0721:            // but there's no other way in Java
0722:            private void intLoop(RasterAccessor src, Rectangle destRect,
0723:                    RasterAccessor dst, int xpos[], int ypos[],
0724:                    int xfracvalues[], int yfracvalues[]) {
0725:
0726:                int srcPixelStride = src.getPixelStride();
0727:                int srcScanlineStride = src.getScanlineStride();
0728:
0729:                int dwidth = destRect.width;
0730:                int dheight = destRect.height;
0731:                int dnumBands = dst.getNumBands();
0732:                int dstDataArrays[][] = dst.getIntDataArrays();
0733:                int dstBandOffsets[] = dst.getBandOffsets();
0734:                int dstPixelStride = dst.getPixelStride();
0735:                int dstScanlineStride = dst.getScanlineStride();
0736:
0737:                int srcDataArrays[][] = src.getIntDataArrays();
0738:                int bandOffsets[] = src.getBandOffsets();
0739:
0740:                int dstOffset = 0;
0741:
0742:                int posy, posylow, posyhigh, posyhigh2;
0743:                int posx, posxlow, posxhigh, posxhigh2;
0744:                long xfrac, yfrac;
0745:                int s__, s_0, s_1, s_2;
0746:                int s0_, s00, s01, s02;
0747:                int s1_, s10, s11, s12;
0748:                int s2_, s20, s21, s22;
0749:                int s;
0750:
0751:                // Putting band loop outside
0752:                for (int k = 0; k < dnumBands; k++) {
0753:                    int dstData[] = dstDataArrays[k];
0754:                    int srcData[] = srcDataArrays[k];
0755:                    int dstScanlineOffset = dstBandOffsets[k];
0756:                    int bandOffset = bandOffsets[k];
0757:
0758:                    for (int j = 0; j < dheight; j++) {
0759:                        int dstPixelOffset = dstScanlineOffset;
0760:                        yfrac = yfracvalues[j];
0761:                        posy = ypos[j] + bandOffset;
0762:                        posylow = posy - srcScanlineStride;
0763:                        posyhigh = posy + srcScanlineStride;
0764:                        posyhigh2 = posyhigh + srcScanlineStride;
0765:                        for (int i = 0; i < dwidth; i++) {
0766:                            xfrac = xfracvalues[i];
0767:                            posx = xpos[i];
0768:                            posxlow = posx - srcPixelStride;
0769:                            posxhigh = posx + srcPixelStride;
0770:                            posxhigh2 = posxhigh + srcPixelStride;
0771:
0772:                            // Get the sixteen surrounding pixel values
0773:                            s__ = srcData[posxlow + posylow];
0774:                            s_0 = srcData[posx + posylow];
0775:                            s_1 = srcData[posxhigh + posylow];
0776:                            s_2 = srcData[posxhigh2 + posylow];
0777:
0778:                            s0_ = srcData[posxlow + posy];
0779:                            s00 = srcData[posx + posy];
0780:                            s01 = srcData[posxhigh + posy];
0781:                            s02 = srcData[posxhigh2 + posy];
0782:
0783:                            s1_ = srcData[posxlow + posyhigh];
0784:                            s10 = srcData[posx + posyhigh];
0785:                            s11 = srcData[posxhigh + posyhigh];
0786:                            s12 = srcData[posxhigh2 + posyhigh];
0787:
0788:                            s2_ = srcData[posxlow + posyhigh2];
0789:                            s20 = srcData[posx + posyhigh2];
0790:                            s21 = srcData[posxhigh + posyhigh2];
0791:                            s22 = srcData[posxhigh2 + posyhigh2];
0792:
0793:                            // Interpolate in X
0794:                            int offsetX = (int) (4 * xfrac);
0795:                            int offsetX1 = offsetX + 1;
0796:                            int offsetX2 = offsetX + 2;
0797:                            int offsetX3 = offsetX + 3;
0798:
0799:                            long sum_ = (long) tableDataHi[offsetX] * s__;
0800:                            sum_ += (long) tableDataHi[offsetX1] * s_0;
0801:                            sum_ += (long) tableDataHi[offsetX2] * s_1;
0802:                            sum_ += (long) tableDataHi[offsetX3] * s_2;
0803:
0804:                            long sum0 = (long) tableDataHi[offsetX] * s0_;
0805:                            sum0 += (long) tableDataHi[offsetX1] * s00;
0806:                            sum0 += (long) tableDataHi[offsetX2] * s01;
0807:                            sum0 += (long) tableDataHi[offsetX3] * s02;
0808:
0809:                            long sum1 = (long) tableDataHi[offsetX] * s1_;
0810:                            sum1 += (long) tableDataHi[offsetX1] * s10;
0811:                            sum1 += (long) tableDataHi[offsetX2] * s11;
0812:                            sum1 += (long) tableDataHi[offsetX3] * s12;
0813:
0814:                            long sum2 = (long) tableDataHi[offsetX] * s2_;
0815:                            sum2 += (long) tableDataHi[offsetX1] * s20;
0816:                            sum2 += (long) tableDataHi[offsetX2] * s21;
0817:                            sum2 += (long) tableDataHi[offsetX3] * s22;
0818:
0819:                            // Intermediate rounding
0820:                            sum_ = (sum_ + round) >> precisionBits;
0821:                            sum0 = (sum0 + round) >> precisionBits;
0822:                            sum1 = (sum1 + round) >> precisionBits;
0823:                            sum2 = (sum2 + round) >> precisionBits;
0824:
0825:                            // Interpolate in Y
0826:                            int offsetY = (int) (4 * yfrac);
0827:                            long sum = (long) tableDataVi[offsetY] * sum_;
0828:                            sum += (long) tableDataVi[offsetY + 1] * sum0;
0829:                            sum += (long) tableDataVi[offsetY + 2] * sum1;
0830:                            sum += (long) tableDataVi[offsetY + 3] * sum2;
0831:
0832:                            s = (int) ((sum + round) >> precisionBits);
0833:
0834:                            dstData[dstPixelOffset] = s;
0835:                            dstPixelOffset += dstPixelStride;
0836:                        }
0837:                        dstScanlineOffset += dstScanlineStride;
0838:                    }
0839:                }
0840:            }
0841:
0842:            private void floatLoop(RasterAccessor src, Rectangle destRect,
0843:                    RasterAccessor dst, int xpos[], int ypos[],
0844:                    int xfracvalues[], int yfracvalues[]) {
0845:
0846:                int srcPixelStride = src.getPixelStride();
0847:                int srcScanlineStride = src.getScanlineStride();
0848:
0849:                int dwidth = destRect.width;
0850:                int dheight = destRect.height;
0851:                int dnumBands = dst.getNumBands();
0852:                float dstDataArrays[][] = dst.getFloatDataArrays();
0853:                int dstBandOffsets[] = dst.getBandOffsets();
0854:                int dstPixelStride = dst.getPixelStride();
0855:                int dstScanlineStride = dst.getScanlineStride();
0856:
0857:                float srcDataArrays[][] = src.getFloatDataArrays();
0858:                int bandOffsets[] = src.getBandOffsets();
0859:
0860:                int dstOffset = 0;
0861:
0862:                int posy, posylow, posyhigh, posyhigh2;
0863:                int posx, posxlow, posxhigh, posxhigh2;
0864:                int xfrac, yfrac;
0865:
0866:                float s__, s_0, s_1, s_2;
0867:                float s0_, s00, s01, s02;
0868:                float s1_, s10, s11, s12;
0869:                float s2_, s20, s21, s22;
0870:
0871:                // Putting band loop outside
0872:                for (int k = 0; k < dnumBands; k++) {
0873:                    float dstData[] = dstDataArrays[k];
0874:                    float srcData[] = srcDataArrays[k];
0875:                    int dstScanlineOffset = dstBandOffsets[k];
0876:                    int bandOffset = bandOffsets[k];
0877:
0878:                    for (int j = 0; j < dheight; j++) {
0879:                        int dstPixelOffset = dstScanlineOffset;
0880:                        yfrac = yfracvalues[j];
0881:                        posy = ypos[j] + bandOffset;
0882:                        posylow = posy - srcScanlineStride;
0883:                        posyhigh = posy + srcScanlineStride;
0884:                        posyhigh2 = posyhigh + srcScanlineStride;
0885:                        for (int i = 0; i < dwidth; i++) {
0886:                            xfrac = xfracvalues[i];
0887:                            posx = xpos[i];
0888:                            posxlow = posx - srcPixelStride;
0889:                            posxhigh = posx + srcPixelStride;
0890:                            posxhigh2 = posxhigh + srcPixelStride;
0891:
0892:                            // Get the sixteen surrounding pixel values
0893:                            s__ = srcData[posxlow + posylow];
0894:                            s_0 = srcData[posx + posylow];
0895:                            s_1 = srcData[posxhigh + posylow];
0896:                            s_2 = srcData[posxhigh2 + posylow];
0897:
0898:                            s0_ = srcData[posxlow + posy];
0899:                            s00 = srcData[posx + posy];
0900:                            s01 = srcData[posxhigh + posy];
0901:                            s02 = srcData[posxhigh2 + posy];
0902:
0903:                            s1_ = srcData[posxlow + posyhigh];
0904:                            s10 = srcData[posx + posyhigh];
0905:                            s11 = srcData[posxhigh + posyhigh];
0906:                            s12 = srcData[posxhigh2 + posyhigh];
0907:
0908:                            s2_ = srcData[posxlow + posyhigh2];
0909:                            s20 = srcData[posx + posyhigh2];
0910:                            s21 = srcData[posxhigh + posyhigh2];
0911:                            s22 = srcData[posxhigh2 + posyhigh2];
0912:
0913:                            // Perform the bicubic interpolation
0914:
0915:                            // Interpolate in X
0916:                            int offsetX = (int) (4 * xfrac);
0917:                            int offsetX1 = offsetX + 1;
0918:                            int offsetX2 = offsetX + 2;
0919:                            int offsetX3 = offsetX + 3;
0920:
0921:                            double sum_ = tableDataHf[offsetX] * s__;
0922:                            sum_ += tableDataHf[offsetX1] * s_0;
0923:                            sum_ += tableDataHf[offsetX2] * s_1;
0924:                            sum_ += tableDataHf[offsetX3] * s_2;
0925:
0926:                            double sum0 = tableDataHf[offsetX] * s0_;
0927:                            sum0 += tableDataHf[offsetX1] * s00;
0928:                            sum0 += tableDataHf[offsetX2] * s01;
0929:                            sum0 += tableDataHf[offsetX3] * s02;
0930:
0931:                            double sum1 = tableDataHf[offsetX] * s1_;
0932:                            sum1 += tableDataHf[offsetX1] * s10;
0933:                            sum1 += tableDataHf[offsetX2] * s11;
0934:                            sum1 += tableDataHf[offsetX3] * s12;
0935:
0936:                            double sum2 = tableDataHf[offsetX] * s2_;
0937:                            sum2 += tableDataHf[offsetX1] * s20;
0938:                            sum2 += tableDataHf[offsetX2] * s21;
0939:                            sum2 += tableDataHf[offsetX3] * s22;
0940:
0941:                            // Interpolate in Y
0942:                            int offsetY = (int) (4 * yfrac);
0943:
0944:                            double sum = tableDataVf[offsetY] * sum_;
0945:                            sum += tableDataVf[offsetY + 1] * sum0;
0946:                            sum += tableDataVf[offsetY + 2] * sum1;
0947:                            sum += tableDataVf[offsetY + 3] * sum2;
0948:
0949:                            if (sum > Float.MAX_VALUE) {
0950:                                sum = Float.MAX_VALUE;
0951:                            } else if (sum < -Float.MAX_VALUE) {
0952:                                sum = -Float.MAX_VALUE;
0953:                            }
0954:
0955:                            dstData[dstPixelOffset] = (float) sum;
0956:                            dstPixelOffset += dstPixelStride;
0957:                        }
0958:                        dstScanlineOffset += dstScanlineStride;
0959:                    }
0960:                }
0961:            }
0962:
0963:            private void doubleLoop(RasterAccessor src, Rectangle destRect,
0964:                    RasterAccessor dst, int xpos[], int ypos[],
0965:                    int xfracvalues[], int yfracvalues[]) {
0966:
0967:                int srcPixelStride = src.getPixelStride();
0968:                int srcScanlineStride = src.getScanlineStride();
0969:
0970:                int dwidth = destRect.width;
0971:                int dheight = destRect.height;
0972:                int dnumBands = dst.getNumBands();
0973:                double dstDataArrays[][] = dst.getDoubleDataArrays();
0974:                int dstBandOffsets[] = dst.getBandOffsets();
0975:                int dstPixelStride = dst.getPixelStride();
0976:                int dstScanlineStride = dst.getScanlineStride();
0977:
0978:                double srcDataArrays[][] = src.getDoubleDataArrays();
0979:                int bandOffsets[] = src.getBandOffsets();
0980:
0981:                int dstOffset = 0;
0982:                int posy, posylow, posyhigh, posyhigh2;
0983:                int posx, posxlow, posxhigh, posxhigh2;
0984:
0985:                double s__, s_0, s_1, s_2;
0986:                double s0_, s00, s01, s02;
0987:                double s1_, s10, s11, s12;
0988:                double s2_, s20, s21, s22;
0989:                double s;
0990:                int xfrac, yfrac;
0991:
0992:                // Putting band loop outside
0993:                for (int k = 0; k < dnumBands; k++) {
0994:                    double dstData[] = dstDataArrays[k];
0995:                    double srcData[] = srcDataArrays[k];
0996:                    int dstScanlineOffset = dstBandOffsets[k];
0997:                    int bandOffset = bandOffsets[k];
0998:
0999:                    for (int j = 0; j < dheight; j++) {
1000:                        int dstPixelOffset = dstScanlineOffset;
1001:                        yfrac = yfracvalues[j];
1002:                        posy = ypos[j] + bandOffset;
1003:                        posylow = posy - srcScanlineStride;
1004:                        posyhigh = posy + srcScanlineStride;
1005:                        posyhigh2 = posyhigh + srcScanlineStride;
1006:                        for (int i = 0; i < dwidth; i++) {
1007:                            xfrac = xfracvalues[i];
1008:                            posx = xpos[i];
1009:                            posxlow = posx - srcPixelStride;
1010:                            posxhigh = posx + srcPixelStride;
1011:                            posxhigh2 = posxhigh + srcPixelStride;
1012:
1013:                            // Get the sixteen surrounding pixel values
1014:                            s__ = srcData[posxlow + posylow];
1015:                            s_0 = srcData[posx + posylow];
1016:                            s_1 = srcData[posxhigh + posylow];
1017:                            s_2 = srcData[posxhigh2 + posylow];
1018:
1019:                            s0_ = srcData[posxlow + posy];
1020:                            s00 = srcData[posx + posy];
1021:                            s01 = srcData[posxhigh + posy];
1022:                            s02 = srcData[posxhigh2 + posy];
1023:
1024:                            s1_ = srcData[posxlow + posyhigh];
1025:                            s10 = srcData[posx + posyhigh];
1026:                            s11 = srcData[posxhigh + posyhigh];
1027:                            s12 = srcData[posxhigh2 + posyhigh];
1028:
1029:                            s2_ = srcData[posxlow + posyhigh2];
1030:                            s20 = srcData[posx + posyhigh2];
1031:                            s21 = srcData[posxhigh + posyhigh2];
1032:                            s22 = srcData[posxhigh2 + posyhigh2];
1033:
1034:                            // Perform the bicubic interpolation
1035:
1036:                            // Interpolate in X
1037:                            int offsetX = (int) (4 * xfrac);
1038:                            int offsetX1 = offsetX + 1;
1039:                            int offsetX2 = offsetX + 2;
1040:                            int offsetX3 = offsetX + 3;
1041:
1042:                            double sum_ = tableDataHd[offsetX] * s__;
1043:                            sum_ += tableDataHd[offsetX1] * s_0;
1044:                            sum_ += tableDataHd[offsetX2] * s_1;
1045:                            sum_ += tableDataHd[offsetX3] * s_2;
1046:
1047:                            double sum0 = tableDataHd[offsetX] * s0_;
1048:                            sum0 += tableDataHd[offsetX1] * s00;
1049:                            sum0 += tableDataHd[offsetX2] * s01;
1050:                            sum0 += tableDataHd[offsetX3] * s02;
1051:
1052:                            double sum1 = tableDataHd[offsetX] * s1_;
1053:                            sum1 += tableDataHd[offsetX1] * s10;
1054:                            sum1 += tableDataHd[offsetX2] * s11;
1055:                            sum1 += tableDataHd[offsetX3] * s12;
1056:
1057:                            double sum2 = tableDataHd[offsetX] * s2_;
1058:                            sum2 += tableDataHd[offsetX1] * s20;
1059:                            sum2 += tableDataHd[offsetX2] * s21;
1060:                            sum2 += tableDataHd[offsetX3] * s22;
1061:
1062:                            // Interpolate in Y
1063:                            int offsetY = (int) (4 * yfrac);
1064:                            s = tableDataVd[offsetY] * sum_;
1065:                            s += tableDataVd[offsetY + 1] * sum0;
1066:                            s += tableDataVd[offsetY + 2] * sum1;
1067:                            s += tableDataVd[offsetY + 3] * sum2;
1068:
1069:                            dstData[dstPixelOffset] = s;
1070:                            dstPixelOffset += dstPixelStride;
1071:                        }
1072:                        dstScanlineOffset += dstScanlineStride;
1073:                    }
1074:                }
1075:            }
1076:
1077:            private synchronized void initTableDataI() {
1078:                if (tableDataHi == null || tableDataVi == null) {
1079:                    tableDataHi = interpTable.getHorizontalTableData();
1080:                    tableDataVi = interpTable.getVerticalTableData();
1081:                }
1082:            }
1083:
1084:            private synchronized void initTableDataF() {
1085:                if (tableDataHf == null || tableDataVf == null) {
1086:                    tableDataHf = interpTable.getHorizontalTableDataFloat();
1087:                    tableDataVf = interpTable.getVerticalTableDataFloat();
1088:                }
1089:            }
1090:
1091:            private synchronized void initTableDataD() {
1092:                if (tableDataHd == null || tableDataVd == null) {
1093:                    tableDataHd = interpTable.getHorizontalTableDataDouble();
1094:                    tableDataVd = interpTable.getVerticalTableDataDouble();
1095:                }
1096:            }
1097:
1098:            //     public static OpImage createTestImage(OpImageTester oit) {
1099:            //         Interpolation interp =
1100:            //             Interpolation.getInstance(Interpolation.INTERP_BICUBIC);
1101:            //         return new ScaleBicubicOpImage(oit.getSource(), null, null,
1102:            //                                        new ImageLayout(oit.getSource()),
1103:            //                                        2.5F, 2.5F, 0.0F, 0.0F,
1104:            //                                        interp);
1105:            //     }
1106:
1107:            //     public static void main(String args[]) {
1108:
1109:            // 	String classname = "com.sun.media.jai.opimage.ScaleBicubicOpImage";
1110:            // 	OpImageTester.performDiagnostics(classname,args);
1111:            // 	System.exit(1);
1112:
1113:            // 	System.out.println("ScaleOpImage Test");
1114:            //         ImageLayout layout;
1115:            //         OpImage src, dst;
1116:            //         Rectangle rect = new Rectangle(2, 2, 5, 5);
1117:
1118:            // 	InterpolationBicubic interp = new InterpolationBicubic(8);
1119:
1120:            //         System.out.println("1. PixelInterleaved short 3-band");
1121:            //         layout = OpImageTester.createImageLayout(0, 0, 200, 200, 0, 0,
1122:            // 						 64, 64, DataBuffer.TYPE_SHORT,
1123:            // 						 3, false);
1124:            //         src = OpImageTester.createRandomOpImage(layout);
1125:            //         dst = new ScaleBicubicOpImage(src, null, null, null,
1126:            //                                       2.0F, 2.0F, 0.0F, 0.0F, interp);
1127:            //         OpImageTester.testOpImage(dst, rect);
1128:            //         OpImageTester.timeOpImage(dst, 10);
1129:
1130:            // 	System.out.println("2. PixelInterleaved ushort 3-band");
1131:            //         layout = OpImageTester.createImageLayout(0, 0, 512, 512, 0, 0,
1132:            // 						 200, 200, 
1133:            // 						 DataBuffer.TYPE_USHORT, 
1134:            // 						 3, false);
1135:            //         src = OpImageTester.createRandomOpImage(layout);
1136:            //         dst = new ScaleBicubicOpImage(src, null, null, null,
1137:            //                                       2.0F, 2.0F, 0.0F, 0.0F, interp);
1138:            //         OpImageTester.testOpImage(dst, rect);
1139:            //         OpImageTester.timeOpImage(dst, 10);
1140:            //     }
1141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.