Type5ShadingContext.java (pdfbox-2.0.23-src) | : | Type5ShadingContext.java (pdfbox-2.0.24-src) | ||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | |||
* limitations under the License. | * limitations under the License. | |||
*/ | */ | |||
package org.apache.pdfbox.pdmodel.graphics.shading; | package org.apache.pdfbox.pdmodel.graphics.shading; | |||
import java.awt.Rectangle; | import java.awt.Rectangle; | |||
import java.awt.geom.AffineTransform; | import java.awt.geom.AffineTransform; | |||
import java.awt.geom.Point2D; | ||||
import java.awt.image.ColorModel; | import java.awt.image.ColorModel; | |||
import java.io.EOFException; | ||||
import java.io.IOException; | import java.io.IOException; | |||
import java.util.ArrayList; | ||||
import java.util.Collections; | ||||
import java.util.List; | ||||
import javax.imageio.stream.ImageInputStream; | ||||
import javax.imageio.stream.MemoryCacheImageInputStream; | ||||
import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | |||
import org.apache.pdfbox.cos.COSDictionary; | ||||
import org.apache.pdfbox.cos.COSStream; | ||||
import org.apache.pdfbox.pdmodel.common.PDRange; | ||||
import org.apache.pdfbox.util.Matrix; | import org.apache.pdfbox.util.Matrix; | |||
/** | /** | |||
* AWT PaintContext for Gouraud Triangle Lattice (Type 5) shading. | * AWT PaintContext for Gouraud Triangle Lattice (Type 5) shading. | |||
* | * | |||
* @author Tilman Hausherr | * @author Tilman Hausherr | |||
* @author Shaola Ren | * @author Shaola Ren | |||
*/ | */ | |||
class Type5ShadingContext extends GouraudShadingContext | class Type5ShadingContext extends GouraudShadingContext | |||
{ | { | |||
skipping to change at line 63 | skipping to change at line 54 | |||
* @param matrix the pattern matrix concatenated with that of the parent con tent stream | * @param matrix the pattern matrix concatenated with that of the parent con tent stream | |||
* @throws IOException if something went wrong | * @throws IOException if something went wrong | |||
*/ | */ | |||
Type5ShadingContext(PDShadingType5 shading, ColorModel cm, AffineTransform x form, | Type5ShadingContext(PDShadingType5 shading, ColorModel cm, AffineTransform x form, | |||
Matrix matrix, Rectangle deviceBounds) throws IOE xception | Matrix matrix, Rectangle deviceBounds) throws IOE xception | |||
{ | { | |||
super(shading, cm, xform, matrix); | super(shading, cm, xform, matrix); | |||
LOG.debug("Type5ShadingContext"); | LOG.debug("Type5ShadingContext"); | |||
setTriangleList(collectTriangles(shading, xform, matrix)); | setTriangleList(shading.collectTriangles(xform, matrix)); | |||
createPixelTable(deviceBounds); | createPixelTable(deviceBounds); | |||
} | } | |||
private List<ShadedTriangle> collectTriangles(PDShadingType5 latticeTriangle | ||||
ShadingType, | ||||
AffineTransform xform, Matrix matrix) throws IOException | ||||
{ | ||||
COSDictionary dict = latticeTriangleShadingType.getCOSObject(); | ||||
if (!(dict instanceof COSStream)) | ||||
{ | ||||
return Collections.emptyList(); | ||||
} | ||||
PDRange rangeX = latticeTriangleShadingType.getDecodeForParameter(0); | ||||
PDRange rangeY = latticeTriangleShadingType.getDecodeForParameter(1); | ||||
if (Float.compare(rangeX.getMin(), rangeX.getMax()) == 0 || | ||||
Float.compare(rangeY.getMin(), rangeY.getMax()) == 0) | ||||
{ | ||||
return Collections.emptyList(); | ||||
} | ||||
int numPerRow = latticeTriangleShadingType.getVerticesPerRow(); | ||||
PDRange[] colRange = new PDRange[numberOfColorComponents]; | ||||
for (int i = 0; i < numberOfColorComponents; ++i) | ||||
{ | ||||
colRange[i] = latticeTriangleShadingType.getDecodeForParameter(2 + i | ||||
); | ||||
} | ||||
List<Vertex> vlist = new ArrayList<Vertex>(); | ||||
long maxSrcCoord = (long) Math.pow(2, bitsPerCoordinate) - 1; | ||||
long maxSrcColor = (long) Math.pow(2, bitsPerColorComponent) - 1; | ||||
COSStream cosStream = (COSStream) dict; | ||||
ImageInputStream mciis = new MemoryCacheImageInputStream(cosStream.creat | ||||
eInputStream()); | ||||
try | ||||
{ | ||||
boolean eof = false; | ||||
while (!eof) | ||||
{ | ||||
Vertex p; | ||||
try | ||||
{ | ||||
p = readVertex(mciis, maxSrcCoord, maxSrcColor, rangeX, rang | ||||
eY, colRange, matrix, xform); | ||||
vlist.add(p); | ||||
} | ||||
catch (EOFException ex) | ||||
{ | ||||
eof = true; | ||||
} | ||||
} | ||||
} | ||||
finally | ||||
{ | ||||
mciis.close(); | ||||
} | ||||
int rowNum = vlist.size() / numPerRow; | ||||
Vertex[][] latticeArray = new Vertex[rowNum][numPerRow]; | ||||
List<ShadedTriangle> list = new ArrayList<ShadedTriangle>(); | ||||
if (rowNum < 2) | ||||
{ | ||||
// must have at least two rows; if not, return empty list | ||||
return list; | ||||
} | ||||
for (int i = 0; i < rowNum; i++) | ||||
{ | ||||
for (int j = 0; j < numPerRow; j++) | ||||
{ | ||||
latticeArray[i][j] = vlist.get(i * numPerRow + j); | ||||
} | ||||
} | ||||
for (int i = 0; i < rowNum - 1; i++) | ||||
{ | ||||
for (int j = 0; j < numPerRow - 1; j++) | ||||
{ | ||||
Point2D[] ps = new Point2D[] { | ||||
latticeArray[i][j].point, | ||||
latticeArray[i][j + 1].point, | ||||
latticeArray[i + 1][j].point }; | ||||
float[][] cs = new float[][] { | ||||
latticeArray[i][j].color, | ||||
latticeArray[i][j + 1].color, | ||||
latticeArray[i + 1][j].color }; | ||||
list.add(new ShadedTriangle(ps, cs)); | ||||
ps = new Point2D[] { | ||||
latticeArray[i][j + 1].point, | ||||
latticeArray[i + 1][j].point, | ||||
latticeArray[i + 1][j + 1].point }; | ||||
cs = new float[][]{ | ||||
latticeArray[i][j + 1].color, | ||||
latticeArray[i + 1][j].color, | ||||
latticeArray[i + 1][j + 1].color }; | ||||
list.add(new ShadedTriangle(ps, cs)); | ||||
} | ||||
} | ||||
return list; | ||||
} | ||||
} | } | |||
End of changes. 6 change blocks. | ||||
112 lines changed or deleted | 2 lines changed or added |