"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/PDShadingType5.java" between
pdfbox-2.0.23-src.zip and pdfbox-2.0.24-src.zip

About: Apache PDFBox is a Java PDF library tool that allows creation of new PDF documents, manipulation of existing documents and the ability to extract content from documents.

PDShadingType5.java  (pdfbox-2.0.23-src):PDShadingType5.java  (pdfbox-2.0.24-src)
skipping to change at line 20 skipping to change at line 20
* *
* 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.Paint; import java.awt.Paint;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.io.EOFException;
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.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSName;
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;
/** /**
* Resources for a shading type 5 (Lattice-Form Gouraud-Shade Triangle Mesh). * Resources for a shading type 5 (Lattice-Form Gouraud-Shade Triangle Mesh).
*/ */
public class PDShadingType5 extends PDTriangleBasedShadingType public class PDShadingType5 extends PDTriangleBasedShadingType
{ {
/** /**
* Constructor using the given shading dictionary. * Constructor using the given shading dictionary.
* *
skipping to change at line 72 skipping to change at line 84
public void setVerticesPerRow(int verticesPerRow) public void setVerticesPerRow(int verticesPerRow)
{ {
getCOSObject().setInt(COSName.VERTICES_PER_ROW, verticesPerRow); getCOSObject().setInt(COSName.VERTICES_PER_ROW, verticesPerRow);
} }
@Override @Override
public Paint toPaint(Matrix matrix) public Paint toPaint(Matrix matrix)
{ {
return new Type5ShadingPaint(this, matrix); return new Type5ShadingPaint(this, matrix);
} }
@SuppressWarnings("squid:S1166")
@Override
List<ShadedTriangle> collectTriangles(AffineTransform xform, Matrix matrix)
throws IOException
{
COSDictionary dict = getCOSObject();
if (!(dict instanceof COSStream))
{
return Collections.emptyList();
}
PDRange rangeX = getDecodeForParameter(0);
PDRange rangeY = getDecodeForParameter(1);
if (Float.compare(rangeX.getMin(), rangeX.getMax()) == 0 ||
Float.compare(rangeY.getMin(), rangeY.getMax()) == 0)
{
return Collections.emptyList();
}
int numPerRow = getVerticesPerRow();
PDRange[] colRange = new PDRange[getNumberOfColorComponents()];
for (int i = 0; i < colRange.length; ++i)
{
colRange[i] = getDecodeForParameter(2 + i);
}
List<Vertex> vlist = new ArrayList<Vertex>();
long maxSrcCoord = (long) Math.pow(2, getBitsPerCoordinate()) - 1;
long maxSrcColor = (long) Math.pow(2, getBitsPerComponent()) - 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);
}
}
Point2D[] ps = new Point2D[3]; // array will be shallow-cloned in Shaded
Triangle constructor
float[][] cs = new float[3][];
for (int i = 0; i < rowNum - 1; i++)
{
for (int j = 0; j < numPerRow - 1; j++)
{
ps[0] = latticeArray[i][j].point;
ps[1] = latticeArray[i][j + 1].point;
ps[2] = latticeArray[i + 1][j].point;
cs[0] = latticeArray[i][j].color;
cs[1] = latticeArray[i][j + 1].color;
cs[2] = latticeArray[i + 1][j].color;
list.add(new ShadedTriangle(ps, cs));
ps[0] = latticeArray[i][j + 1].point;
ps[1] = latticeArray[i + 1][j].point;
ps[2] = latticeArray[i + 1][j + 1].point;
cs[0] = latticeArray[i][j + 1].color;
cs[1] = latticeArray[i + 1][j].color;
cs[2] = latticeArray[i + 1][j + 1].color;
list.add(new ShadedTriangle(ps, cs));
}
}
return list;
}
} }
 End of changes. 3 change blocks. 
0 lines changed or deleted 111 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)