}
//TODO missing: BBox, AntiAlias (p. 305 in 1.7 spec)
// p318:
// reading in sequence from higher-order to lower-order bit positions
ImageInputStream mciis = new MemoryCacheImageInputStream(cosStream.getUnfilteredStream());
while (true)
{
try
{
byte flag = (byte) (mciis.readBits(bitsPerFlag) & 3);
LOG.debug("flag: " + flag);
switch (flag)
{
case 0:
Vertex v1 = readVertex(mciis, flag, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRangeTab);
Vertex v2 = readVertex(mciis, (byte) mciis.readBits(bitsPerFlag), maxSrcCoord, maxSrcColor,
rangeX, rangeY, colRangeTab);
Vertex v3 = readVertex(mciis, (byte) mciis.readBits(bitsPerFlag), maxSrcCoord, maxSrcColor,
rangeX, rangeY, colRangeTab);
// add them after they're read, so that they are never added if there is a premature EOF
vertexList.add(v1);
vertexList.add(v2);
vertexList.add(v3);
break;
case 1:
case 2:
vertexList.add(readVertex(mciis, flag, maxSrcCoord, maxSrcColor, rangeX, rangeY, colRangeTab));
break;
default:
LOG.warn("bad flag: " + flag);
break;
}
}
catch (EOFException ex)
{
LOG.debug("EOF");
if (vertexList.size() < 3)
{
LOG.warn("Incomplete mesh is ignored");
vertexList.clear();
}
else if (vertexList.size() > 1 && vertexList.get(0).flag != 0)
{
LOG.warn("Mesh with incorrect start flag " + vertexList.get(0).flag + " is ignored");
vertexList.clear();
}
// check that there are 3 entries if there is a 0 flag
int vi = 0;
while (vi < vertexList.size())
{
if (vertexList.get(vi).flag == 0)
{
if (vi + 2 >= vertexList.size())
{
LOG.warn("Mesh with incomplete triangle");
// remove rest
while (vertexList.size() >= vi + 1)
{
vertexList.remove(vi);
}
break;
}
vi += 3;
}
else
{
++vi;
}
}
break;
}
}
mciis.close();
transformVertices(vertexList, ctm, xform, pageHeight);
createTriangleList(vertexList);
}