1 7 8 package com.sun.imageio.plugins.common; 9 10 import java.awt.Point ; 11 import java.awt.Rectangle ; 12 13 20 public class ReaderUtil { 21 22 private static void computeUpdatedPixels(int sourceOffset, 24 int sourceExtent, 25 int destinationOffset, 26 int dstMin, 27 int dstMax, 28 int sourceSubsampling, 29 int passStart, 30 int passExtent, 31 int passPeriod, 32 int[] vals, 33 int offset) 34 { 35 64 boolean gotPixel = false; 65 int firstDst = -1; 66 int secondDst = -1; 67 int lastDst = -1; 68 69 for (int i = 0; i < passExtent; i++) { 70 int src = passStart + i*passPeriod; 71 if (src < sourceOffset) { 72 continue; 73 } 74 if ((src - sourceOffset) % sourceSubsampling != 0) { 75 continue; 76 } 77 if (src >= sourceOffset + sourceExtent) { 78 break; 79 } 80 81 int dst = destinationOffset + 82 (src - sourceOffset)/sourceSubsampling; 83 if (dst < dstMin) { 84 continue; 85 } 86 if (dst > dstMax) { 87 break; 88 } 89 90 if (!gotPixel) { 91 firstDst = dst; gotPixel = true; 93 } else if (secondDst == -1) { 94 secondDst = dst; } 96 lastDst = dst; } 98 99 vals[offset] = firstDst; 100 101 if (!gotPixel) { 103 vals[offset + 2] = 0; 104 } else { 105 vals[offset + 2] = lastDst - firstDst + 1; 106 } 107 108 vals[offset + 4] = Math.max(secondDst - firstDst, 1); 110 } 111 112 155 public static int[] computeUpdatedPixels(Rectangle sourceRegion, 156 Point destinationOffset, 157 int dstMinX, 158 int dstMinY, 159 int dstMaxX, 160 int dstMaxY, 161 int sourceXSubsampling, 162 int sourceYSubsampling, 163 int passXStart, 164 int passYStart, 165 int passWidth, 166 int passHeight, 167 int passPeriodX, 168 int passPeriodY) 169 { 170 int[] vals = new int[6]; 171 computeUpdatedPixels(sourceRegion.x, sourceRegion.width, 172 destinationOffset.x, 173 dstMinX, dstMaxX, sourceXSubsampling, 174 passXStart, passWidth, passPeriodX, 175 vals, 0); 176 computeUpdatedPixels(sourceRegion.y, sourceRegion.height, 177 destinationOffset.y, 178 dstMinY, dstMaxY, sourceYSubsampling, 179 passYStart, passHeight, passPeriodY, 180 vals, 1); 181 return vals; 182 } 183 } 184 | Popular Tags |