// sofnSegment.width, sofnSegment.height);
}
else
throw new ImageReadException(sofnSegment.numberOfComponents +
" components are invalid or unsupported");
DataBuffer dataBuffer = raster.getDataBuffer();
for (int y1 = 0; y1 < vSize*yMCUs; y1 += vSize)
{
for (int x1 = 0; x1 < hSize*xMCUs; x1 += hSize)
{
readMCU(bitInputStream, preds, mcu);
rescaleMCU(mcu, hSize, vSize, scaledMCU);
int srcRowOffset = 0;
int dstRowOffset = y1*sofnSegment.width + x1;
for (int y2 = 0; y2 < vSize && y1 + y2 < sofnSegment.height; y2++)
{
for (int x2 = 0; x2 < hSize && x1 + x2 < sofnSegment.width; x2++)
{
if (scaledMCU.length == 3)
{
int Y = scaledMCU[0].samples[srcRowOffset + x2];
int Cb = scaledMCU[1].samples[srcRowOffset + x2];
int Cr = scaledMCU[2].samples[srcRowOffset + x2];
int rgb = YCbCrConverter.convertYCbCrToRGB(Y, Cb, Cr);
dataBuffer.setElem(dstRowOffset + x2, rgb);
}
else if (mcu.length == 1)
{
int Y = scaledMCU[0].samples[srcRowOffset + x2];
dataBuffer.setElem(dstRowOffset + x2,
(Y << 16) | (Y << 8) | Y);
}
else
throw new ImageReadException("Unsupported JPEG with " +
mcu.length + " components");