0

I used this link and added lots of enhancements related to GDI. https://github.com/microsoft/Windows-driver-samples/tree/master/print/OEM%20Printer%20Customization%20Plug-in%20Samples/C%2B%2B/bitmap

The above samples generates a bitmap driver with output as a bitmap image. Now using the bitmap I am able to generate working PCL for monochrome. I need some help for enhancing it further to generate PCL for 16bpp, 24 color and gray scale Can anyone suggest some samples where I could see the PCL commands written in C++? The monochrome part works correctly but the remaining color or gray scale just produce a blank image. I am using GhostPCL to convert to jpeg for testing purposes. Can anyone provide a sample for where given an appropriate bitmap there is some PCLstream as output? If you can't provide an entire working sample, how about things in commands which need to be addressed.

The one obvious thing is the buffer, rowsize.

This is the PCL for monochrome. https://mega.nz/file/rNlFFRYL#CDK_l6s9KojLzywI3drsO1yt_OaK7-n5TNWdj1x8Aa4

This is the PCL for TrueColor same document. Nothing is printed except text

https://mega.nz/file/jI0lXRxZ#DmjLiDlNR8CfisN9UsRgz0F-FwXgOC0DCkaRPxqYCh4

I am using ghostPCL to convert to jpeg.

Code for monochrome: //Header

// Universal Exit
    char bufUnivExit[10];
    StringCchPrintfA(bufUnivExit, 10, "%c%s", 27, "%-12345X");  // 9 chars
    MoveMemory(pOemPDEV->pBufStart, bufUnivExit, 10);
    dwOffset += 9;

    // PJL
    char bufPJL[38];
    StringCchPrintfA(bufPJL, 38, "%s%c%c", "@PJL COMMENT ROMFOBMAYCE TEST-PRINT", 13, 10); // 37 chars
    MoveMemory(pOemPDEV->pBufStart + dwOffset, bufPJL, 38);
    dwOffset += 37;

    // PCL Esc
    char bufEsc[3];
    StringCchPrintfA(bufEsc, 3, "%c%s", 27, "E");   // 2 chars
    MoveMemory(pOemPDEV->pBufStart + dwOffset, bufEsc, 3);
    dwOffset += 2;

    // Raster Res
    char bufRes[8];
    StringCchPrintfA(bufRes, 8, "%c%s%d%s", 27, "*t", pPubDM->dmYResolution, "R");  // 7 chars
    MoveMemory(pOemPDEV->pBufStart + dwOffset, bufRes, 8);
    dwOffset += 7;

    // Units of Measure
    char bufUOM[8];
    StringCchPrintfA(bufUOM, 8, "%c%s%d%s", 27, "&u", pPubDM->dmYResolution, "D");  // 7 chars
    MoveMemory(pOemPDEV->pBufStart + dwOffset, bufUOM, 8);
    dwOffset += 7;

    // Raster Presentation
    char bufPres[6];
    StringCchPrintfA(bufPres, 6, "%c%s", 27, "*r3F"); // 5 chars
    MoveMemory(pOemPDEV->pBufStart + dwOffset, bufPres, 6);
    dwOffset += 5;

    // Orientation
    char bufOrient[6];
    if (pPubDM->dmOrientation == 1)
        orient = 0;
    else
        orient = 1;
    StringCchPrintfA(bufOrient, 6, "%c%s%d%s", 27, "&l", orient, "O");  // 5 chars
    MoveMemory(pOemPDEV->pBufStart + dwOffset, bufOrient, 6);
    dwOffset += 5;

    // Paper Size
    char bufPaperSize[6];
    if (pPubDM->dmPaperSize == 1)
        pageSize = 2;
    else
        pageSize = 3;
    StringCchPrintfA(bufPaperSize, 6, "%c%s%d%s", 27, "&l", pageSize, "A"); // 5 chars
    MoveMemory(pOemPDEV->pBufStart + dwOffset, bufPaperSize, 6);
    dwOffset += 5;

    // Set horizontal and vertical registration (page margins)
    char bufRegistration[14];
    StringCchPrintfA(bufRegistration, 14, "%c%s", 27, "&l-180u-360Z");  // 13 chars
    MoveMemory(pOemPDEV->pBufStart + dwOffset, bufRegistration, 14);
        dwOffset += 13;

//Code for Page
BYTE bitmapRow[1050];
    BYTE compRow[2100];
    DWORD dwRowSize = 0;
    DWORD dwCompPCLBitmapSize = 0;
    for (i = 0; i < pso->sizlBitmap.cy; i++) {
            // Zero Memory hack for bottom of form black line
            if (*(((PBYTE &)pso->pvScan0) + (i * pso->lDelta) + 319) == 0xFF)
                ZeroMemory(((PBYTE &)pso->pvScan0) + (i * pso->lDelta), 320);

            // Copy the bitmap scan line into bitmapRow and send them off to be compressed
            ZeroMemory(bitmapRow, 1050);
            ZeroMemory(compRow, 2100);
            MoveMemory(bitmapRow, ((PBYTE &)pso->pvScan0) + (i * pso->lDelta), pso->lDelta);
            dwRowSize = CompressBitmapRow(compRow, bitmapRow, pso->lDelta);

            // Create PCL Row Heading
            char bufPCLLineHead[9];
            StringCchPrintfA(bufPCLLineHead, 9, "%c%s%d%s", 27, "*b", dwRowSize, "W");

            if ((dwCompPCLBitmapSize + dwRowSize + strlen(bufPCLLineHead)) 
                                                        > pOemPDEV->dwCompBitmapBufSize) {
                if (!GrowCompBitmapBuf(pOemPDEV)) {
                    //ZeroMemory(traceBuff, 256);
                    //StringCchPrintf(traceBuff, 256, 
                    //      L"Compressed bitmap buffer could not allocate more memory.");
                    //WriteTraceLine(traceBuff);
                }
            }

            if (pOemPDEV->pCompBitmapBufStart) {
                // write the PCL line heading to the buffer
                MoveMemory(pOemPDEV->pCompBitmapBufStart + dwCompPCLBitmapSize, 
                                        bufPCLLineHead, strlen(bufPCLLineHead));
                dwCompPCLBitmapSize += strlen(bufPCLLineHead);

                // write the compressed row to the buffer
                MoveMemory(pOemPDEV->pCompBitmapBufStart + dwCompPCLBitmapSize, 
                                        compRow, dwRowSize);
                dwCompPCLBitmapSize += dwRowSize;       
            }
        }

        // Calculate size and create buffer 
        dwPageBufferSize = 21;

        if (!firstPage)
            dwPageBufferSize++;

        bGrowBuffer(pOemPDEV, dwPageBufferSize);

        // Add all Raster Header Lines
        if (!firstPage) 
        {
            // Add a Form Feed
            char bufFormFeed[2];
            StringCchPrintfA(bufFormFeed, 2, "%c", 12);             // 1 char
            MoveMemory(pOemPDEV->pBufStart + dwOffset, bufFormFeed, 2);
            dwOffset += 1;
        }

        // Position cursor at X0, Y0
        char bufXY[8];
        StringCchPrintfA(bufXY, 8, "%c%s", 27, "*p0x0Y");           // 7 chars
        MoveMemory(pOemPDEV->pBufStart + dwOffset, bufXY, 8);
        dwOffset += 7;

        // Start Raster Graphics
        char bufStartRas[6];
        StringCchPrintfA(bufStartRas, 6, "%c%s", 27, "*r1A");       // 5 chars
        MoveMemory(pOemPDEV->pBufStart + dwOffset, bufStartRas, 6);
        dwOffset += 5;

        // Raster Encoding - Run-Length Encoding
        char bufRasEncoding[6];
        StringCchPrintfA(bufRasEncoding, 6, "%c%s", 27, "*b1M");    // 5 chars
        MoveMemory(pOemPDEV->pBufStart + dwOffset, bufRasEncoding, 6);
        dwOffset += 5;

        // Write out bitmap header PCL
        dwWritten = pDevObj->pDrvProcs->DrvWriteSpoolBuf(pDevObj, pOemPDEV->pBufStart, dwPageBufferSize);

        // Write out PCL plus compressed bitmap bytes
        dwWritten = pDevObj->pDrvProcs->DrvWriteSpoolBuf(pDevObj, pOemPDEV->pCompBitmapBufStart, dwCompPCLBitmapSize);

        // End Raster Graphics
        char bufEndRas[5];
        StringCchPrintfA(bufEndRas, 5, "%c%s", 27, "*rB");          // 4 chars
        MoveMemory(pOemPDEV->pBufStart + dwOffset, bufEndRas, 5);

        // Write out PCL end bitmap
        dwWritten = pDevObj->pDrvProcs->DrvWriteSpoolBuf(pDevObj, bufEndRas, 4);

Can anyone suggest? I don't have working knowledge of PCL or C++ except learning it like this.

user575219
  • 2,346
  • 15
  • 54
  • 105
  • @Señor CMasMas-Reinstate Monica: Can you suggest sir? I have a some monochrome PCL but converting it to color. I have 0 PCL experience. Any help on what commands inorder to be able to support gray, 16bpp, 24bpp would be great – user575219 May 03 '20 at 00:52
  • @ Señor CMasMas-Reinstate Monica: Thanks – user575219 May 03 '20 at 00:52
  • @Douglas Anderson: Sir, I have seen you helping people about PCL. Can you guide me here – user575219 May 03 '20 at 00:57

0 Answers0