//--------------------------------------------------------------------// // M e t h o d // // g e n e r a t e I m a g e D a t a // //--------------------------------------------------------------------// // // // Generate ReadImage operator(s) and associated embedded data. // // // //--------------------------------------------------------------------// private static void generateImageData(BinaryWriter prnWriter, UInt16 srcBitsPerPixel, Int32 srcWidth, Int32 srcHeight) { const Int32 maxImageBlock = 2048; const Int32 sizeStd = 64; Byte[] bufStd = new Byte[sizeStd]; Int32 indStd = 0; Boolean firstBlock = true, indexed = true; Int32 bytesPerRow, padBytes; Int32 imageCrntLine, imageHeight, imageRowMult, imageBlockHeight, imageBlockSize; //------------------------------------------------------------// if (srcBitsPerPixel == 1) { indexed = true; bytesPerRow = srcWidth / 8; if ((srcWidth % 8) != 0) { bytesPerRow++; } } else if (srcBitsPerPixel == 4) { indexed = true; bytesPerRow = srcWidth / 2; if ((srcWidth % 2) != 0) { bytesPerRow++; } } else // if (srcBitsPerPixel == 24) { indexed = false; bytesPerRow = srcWidth * 3; } padBytes = bytesPerRow % 4; if (padBytes != 0) { padBytes = 4 - padBytes; bytesPerRow += padBytes; } imageCrntLine = 0; imageHeight = srcHeight; imageRowMult = (Int32)Math.Floor((Double)maxImageBlock / (Double)bytesPerRow); if (imageRowMult == 0) { imageRowMult = 1; } Byte[] bufSub = new Byte[bytesPerRow]; for (Int32 i = 0; i < imageHeight; i += imageRowMult) { if ((imageCrntLine + imageRowMult) >= imageHeight) { imageBlockHeight = imageHeight - imageCrntLine; } else { imageBlockHeight = imageRowMult; } imageBlockSize = imageBlockHeight * bytesPerRow; PCLXLWriter.addAttrUint16(ref bufStd, ref indStd, PCLXLAttributes.eTag.StartLine, (UInt16)imageCrntLine); PCLXLWriter.addAttrUint16(ref bufStd, ref indStd, PCLXLAttributes.eTag.BlockHeight, (UInt16)imageBlockHeight); PCLXLWriter.addAttrUbyte(ref bufStd, ref indStd, PCLXLAttributes.eTag.CompressMode, (Byte)PCLXLAttrEnums.eVal.eNoCompression); PCLXLWriter.addOperator(ref bufStd, ref indStd, PCLXLOperators.eTag.ReadImage); PCLXLWriter.addEmbedDataIntro(ref bufStd, ref indStd, imageBlockSize); prnWriter.Write(bufStd, 0, indStd); indStd = 0; for (Int32 j = 0; j < imageRowMult; j++) { if ((i + j) >= imageHeight) { j = imageRowMult; } else { ToolImageBitmapCore.getNextImageBlock(ref bufSub, bytesPerRow, firstBlock); // if (srcBitsPerPixel == 24) if (!indexed) { // change BGR components to RGB // Byte temp; Int32 endLine = bytesPerRow - 2; for (Int32 k = 0; k <= endLine; k += 3) { if (bufSub[k] != bufSub[k + 2]) { temp = bufSub[k]; bufSub[k] = bufSub[k + 2]; bufSub[k + 2] = temp; } } } firstBlock = false; prnWriter.Write(bufSub, 0, bytesPerRow); } } imageCrntLine += imageBlockHeight; } }