⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dj9xxvip.cpp

📁 HP喷墨打印机驱动代码 HP内部资料! 珍贵 珍贵 珍贵
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                while (pEnd > pStr) // take out trailing spaces in JobName before compare                {                    if (*(pEnd-1) == ' ')                    {                        *(pEnd-1) = '\0';                    }                    else                    {                        break;                    }                    pEnd--;                }                if (!strcmp(pStr, OUR_PJL_JOBNAME))                {                    break;                }            }            pSS->BusyWait((DWORD)500);        }        else        {            DBG1("JobName missing from DeviceID strings");            goto cleanup;        }    }    if (i>=maxWaitTries)    {        // printer didn't respond to driverware in PCL3GUI mode withing allowed timeout        DBG1("Printer didn't respond to PJL\n");        goto cleanup;    }    // now printer is in sync with us so try PCL3 mode and expect it to react to command    // immediately or will assume that it ignores driverware in that mode    if (Send((const BYTE*)EnterLanguage,sizeof(EnterLanguage)) != NO_ERROR) goto cleanup;    if (Send((const BYTE*)PCL3,sizeof(PCL3)) != NO_ERROR) goto cleanup;    if (Send((const BYTE*)&LF,1) != NO_ERROR) goto cleanup;    if (Send((const BYTE*)DriverwareJobName,sizeof(DriverwareJobName)) != NO_ERROR) goto cleanup;    if (Flush() != NO_ERROR) goto cleanup;          // we flush our ::Send buffer    if (pSS->FlushIO() != NO_ERROR) goto cleanup;   // we flush any external I/O buffer    // wait for printer to see this and set DeviceID to reflect this command    // since we are sending in PCL3 mode we don't know if printer will respond    // so don't wait very long    maxWaitTries = 4;    for (i=0; i<maxWaitTries; i++)    {        if (pSS->GetDeviceID(devIDBuff, DevIDBuffSize, TRUE) != NO_ERROR)    goto cleanup;        if ( (pStr=(char *)strstr((const char*)devIDBuff+2,";J:")) )        {            pStr += 3;            if ( (pEnd=(char *)strstr((const char*)pStr,";")) )            {                *pEnd = '\0';                // firmware may have garbage in remainder of JobName buffer - truncate                // it to the length of the string that should be set before compare                if (!strncmp(pStr, DRIVERWARE_JOBNAME, strlen(DRIVERWARE_JOBNAME)))                {                    pcl3driverware = TRUE;                    break;                }            }            pSS->BusyWait((DWORD)500);        }        else        {            DBG1("JobName missing from DeviceID string");            goto cleanup;        }    }    if (i>=maxWaitTries)    {        // since we haven't gotten a response assume that the printer ignores driverware        // commands in PCL3 mode        pcl3driverware = FALSE;    }cleanup:    if (inAJob)   // send UEL in case left printer in the context of a job    {        if (Send((const BYTE*)UEL,sizeof(UEL)) != NO_ERROR) goto bailout;        if (pSS->FlushIO() != NO_ERROR) goto bailout;    }bailout:    return pcl3driverware;} //IsPCL3DriverwareAvailableDISPLAY_STATUS DJ9xxVIP::ParseError(BYTE status_reg){    DBG1("DJ9xxVIP, parsing error info\n");    DRIVER_ERROR err = NO_ERROR;    BYTE DevIDBuffer[DevIDBuffSize];    char *pStr;    int     iVersion = pSS->GetVIPVersion ();    if(IOMode.bDevID && iVersion < 6)    {        // If a bi-di cable was plugged in and everything was OK, let's see if it's still        // plugged in and everything is OK        err = pSS->GetDeviceID (DevIDBuffer, DevIDBuffSize, TRUE);        if(err != NO_ERROR)        {            // job was bi-di but now something's messed up, probably cable unplugged            return DISPLAY_COMM_PROBLEM;        }        if ( (pStr=(char *)strstr((const char*)DevIDBuffer+2,";S:")) == NULL )        {            return DISPLAY_COMM_PROBLEM;        }        // point to PrinterState        BYTE b1,b2;        pStr+=5;   // 3 for ";S:", 2 for version -- point to first byte of "printer state"        b1=*pStr;        if (b1=='9')        {            return DISPLAY_TOP_COVER_OPEN;        }        if (iVersion < 3)        {            pStr += 12;     // point to "feature state"        }        else if (iVersion < 5)        {            pStr += 14;        }        else        {            pStr += 18;        }        b1=*pStr++;        b2=*pStr++;        if ((b1=='0') && (b2=='9'))     // 09 = OOP state        {            DBG1("Out of Paper [from Encoded DevID]\n");            return DISPLAY_OUT_OF_PAPER;        }        if (b1 == '0' && (b2 == 'c' || b2 == 'C'))      // 0C - PhotoTray Mismatch        {/* *          PhotoTray is engaged, but requested paper size is larger than A6. *          It may also mean A6/Photo size is requested but photo tray is not engaged. */            DBG1("Photo Tray Mismatch [from Encoded DevID]\n");            return DISPLAY_PHOTOTRAY_MISMATCH;        }//      Paper Jam or Paper Stall        if ((b1 == '1' && b2 == '0') ||        // Paper Jam            (b1 == '0' && (b2 == 'e' || b2 == 'E')))        {            return DISPLAY_PAPER_JAMMED;        }//      Carriage Stall        if (b1 == '0' && (b2 == 'F' || b2 == 'f'))        {            return DISPLAY_ERROR_TRAP;        }//      Job Cancelled (AIO printer turn idle after job canceled)        if ((b1=='0') && (b2=='5'))     // 05 = CNCL state        {            DBG1("Printing Canceled [from Encoded DevID]\n");            return DISPLAY_PRINTING_CANCELED;        }        // VerifyPenInfo will handle prompting the user        // if this is a problem        err = VerifyPenInfo ();        if(err != NO_ERROR)        {            // VerifyPenInfo returned an error, which can only happen when ToDevice            // or GetDeviceID returns an error. Either way, it's BAD_DEVICE_ID or            // IO_ERROR, both unrecoverable.  This is probably due to the printer            // being turned off during printing, resulting in us not being able to            // power it back on in VerifyPenInfo, since the buffer still has a            // partial raster in it and we can't send the power-on command.            return DISPLAY_COMM_PROBLEM;        }    }    // check for errors we can detect from the status reg    if (IOMode.bStatus)    {        // Although DJ8XX is OOP, printer continues taking data and BUSY bit gets        // set.  See IO_defs.h        if ( DEVICE_IS_OOP(status_reg) )        {            DBG1("Out Of Paper [from status byte]\n");            return DISPLAY_OUT_OF_PAPER;        }        // DJ8XX doesn't go offline, so SELECT bit is set even when paper jammed.        // See IO_defs.h        if (DEVICE_PAPER_JAMMED(status_reg))        {            DBG1("Jammed [from status byte]\n");            return DISPLAY_PAPER_JAMMED;        }/* *      Do not process this. Malibu printers set the NFAULT bit low when a pen is *      missing, eventhough they support reserve mode printing. This causes us to *      report ERROR_TRAP message. Consequence is that we may not catch carriage *      stall, but should eventually result in time out.        if (DEVICE_IO_TRAP(status_reg))        {            DBG1("Jammed or trapped [from status byte]\n");            return DISPLAY_ERROR_TRAP;        } */    }    // don't know what the problem is-    //  Is the PrinterAlive?    if (pSS->PrinterIsAlive())    {        iTotal_SLOW_POLL_Count += iMax_SLOW_POLL_Count;#if defined(DEBUG) && (DBG_MASK & DBG_LVL1)        printf("iTotal_SLOW_POLL_Count = %d\n",iTotal_SLOW_POLL_Count);#endif        // -Note that iTotal_SLOW_POLL_Count is a multiple of        //  iMax_SLOW_POLL_Count allowing us to check this        //  on an absolute time limit - not relative to the number        //  of times we happen to have entered ParseError.        // -Also note that we have different thresholds for uni-di & bi-di.        if(            ((IOMode.bDevID == FALSE) && (iTotal_SLOW_POLL_Count >= 60)) ||            ((IOMode.bDevID == TRUE)  && (iTotal_SLOW_POLL_Count >= 120))          )        {            return DISPLAY_BUSY;        }        else        {            return DISPLAY_PRINTING;        }    }    else    {        return DISPLAY_COMM_PROBLEM;    }} //ParseErrorDRIVER_ERROR DJ9xxVIP::CleanPen(){    const BYTE Aladdin_User_Output_Page[] = {ESC, '%','P','u','i','f','p','.',        'm','u','l','t','i','_','b','u','t','t','o','n','_','p','u','s','h',' ','3',';',        'u','d','w','.','q','u','i','t',';',ESC,'%','-','1','2','3','4','5','X' };    DWORD length = sizeof(PEN_CLEAN_PML);    DRIVER_ERROR err = pSS->ToDevice(PEN_CLEAN_PML, &length);    ERRCHECK;    // send this page so that the user sees some output.  If you don't send this, the    // pens get serviced but nothing prints out.    length = sizeof(Aladdin_User_Output_Page);    return pSS->ToDevice(Aladdin_User_Output_Page, &length);} //CleanPen#if defined(APDK_VIP_COLORFILTERING)/// ERNIE ////////////////////////////////////////////////////////////////BOOL TErnieFilter::Process(RASTERDATA* ImageData){	if (ImageData == NULL || (ImageData->rasterdata[COLORTYPE_COLOR] == NULL && ImageData->rasterdata[COLORTYPE_BLACK] == NULL))	{		return FALSE;	}	else	{		if (ImageData->rasterdata[COLORTYPE_COLOR])		{			submitRowToFilter(ImageData->rasterdata[COLORTYPE_COLOR]);			if (ImageData->rasterdata[COLORTYPE_BLACK])			{				memcpy(fBlackRowPtr[RowIndex], ImageData->rasterdata[COLORTYPE_BLACK], ImageData->rastersize[COLORTYPE_BLACK]);			}			BlackRasterSize[RowIndex++] = ImageData->rastersize[COLORTYPE_BLACK];			if (RowIndex == 4)				RowIndex = 0;			// something ready after 4th time only			return (fNumberOfBufferedRows == 0);		}		else		{			iRastersReady = 1;		}	}	return TRUE;} //Processunsigned int TErnieFilter::GetOutputWidth(COLORTYPE  rastercolor){	if (rastercolor == COLORTYPE_COLOR)	{		if (raster.rasterdata[COLORTYPE_COLOR] == NULL)			return 0;		else			return fRowWidthInPixels * BYTES_PER_PIXEL;	}	else	{		if (raster.rasterdata[COLORTYPE_COLOR] == NULL)			return raster.rastersize[rastercolor];		else			return BlackRasterSize[iRastersDelivered-1];	}} //GetOutputWidthBYTE* TErnieFilter::NextOutputRaster(COLORTYPE  rastercolor){	if (iRastersReady == 0)		return (BYTE*)NULL;	if (rastercolor == COLORTYPE_COLOR)	{		if (raster.rasterdata[COLORTYPE_COLOR] == NULL)		{			iRastersReady--;			return (BYTE*)NULL;		}		else		{			if (iRastersReady == 0)				return (BYTE*)NULL;			iRastersReady--;			return fRowPtr[iRastersDelivered++];		}	}	else	{		if (raster.rasterdata[COLORTYPE_COLOR] == NULL)		{			return raster.rasterdata[rastercolor];		}		else		{			if (BlackRasterSize[iRastersDelivered] == 0)				return NULL;			else				return fBlackRowPtr[iRastersDelivered];		}	}} //NextOutputRastervoid TErnieFilter::Flush(){    writeBufferedRows();    iRastersDelivered=0;    fPixelOffsetIndex = 0;    iRastersReady = fNumberOfBufferedRows;    fNumberOfBufferedRows = 0;} //Flush#endif //APDK_VIP_COLORFILTERINGinline uint32_t Mode10::get3Pixel(    BYTE* pixAddress,    int pixelOffset){    pixAddress += ((pixelOffset << 1) + pixelOffset);     //pixAddress += pixelOffset * 3;    BYTE r = *(pixAddress);    BYTE g = *(pixAddress + 1);    BYTE b = *(pixAddress + 2);    return (kWhite & ((r << 16) | (g << 8) | (b)));//  unsigned int toReturn = *((unsigned int*)pixAddress); // load toReturn with XRGB//  toReturn &= kWhite; // Strip off unwanted X. EGW stripped lsb blue.} //get3Pixelvoid Mode10::put3Pixel(    BYTE* pixAddress,    int pixelOffset,    uint32_t pixel){    pixAddress += ((pixelOffset << 1) + pixelOffset);     //pixAddress += pixelOffset * 3;    unsigned int temp = (pixel & kWhite);    *(pixAddress) = ((temp >> 16) & 0x000000FF);    *(pixAddress + 1) = ((temp >> 8) & 0x000000FF);    *(pixAddress + 2) = (temp & 0x000000FF);} //put3Pixelunsigned short Mode10::ShortDelta(    uint32_t lastPixel,    uint32_t lastUpperPixel){    int dr,dg,db;    int result;    dr = GetRed(lastPixel) - GetRed(lastUpperPixel);    dg = GetGreen(lastPixel) - GetGreen(lastUpperPixel);    db = GetBlue(lastPixel) - GetBlue(lastUpperPixel);    if ((dr <= 15) && (dr >= -16) && (dg <= 15) && (dg >= -16) && (db <= 30) && (db >= -32))    {   // Note db is divided by 2 to double it's range from -16..15 to -32..30        result = ((dr << 10) & 0x007C00) | (((dg << 5) & 0x0003E0) | ((db >> 1) & 0x01F) | 0x8000);   // set upper bit to signify short delta    }    else    {        result = 0;  // upper bit is zero to signify delta won't work    }    return result;}BOOL Mode10::Process(    RASTERDATA* input)/****************************************************************************Initially written by Elden WoodAugust 1998Similar to mode 9, though tailored for pixel data.For more information see the Bert Compression Format document.This function compresses a single row per call.****************************************************************************/{    if (input==NULL || 		(input->rasterdata[COLORTYPE_COLOR]==NULL && input->rasterdata[COLORTYPE_BLACK]==NULL))    // flushing pipeline    {        Flush();        return FALSE;    }	if (myplane == COLORTYPE_BLACK || input->rasterdata[COLORTYPE_COLOR]==NULL)	{		iRastersReady = 1;		compressedsize = 0;		if (seeded)		{			thePrinter->Send(ResetSeedrow, sizeof(ResetSeedrow));			seeded = FALSE;		}		return TRUE;	}    unsigned int originalsize = input->rastersize[myplane];	unsigned int size = input->rastersize[myplane];    unsigned char *seedRowPtr = (unsigned char*)SeedRow;    unsigned char *compressedDataPtr = compressBuf;    unsigned char *curRowPtr =  (unsigned char*)input->rasterdata[myplane];    unsigned int rowWidthInBytes = size;    ASSERT(curRowPtr);    ASSERT(seedRowPtr);    ASSERT(compressedDataPtr);    ASSERT(rowWidthInBytes >= BYTES_PER_PIXEL);    ASSERT((rowWidthInBytes % BYTES_PER_PIXEL) == 0);    unsigned char *compressedDataStart = compressedDataPtr;    unsigned int lastPixel = (rowWidthInBytes / BYTES_PER_PIXEL) - 1;    // Setup sentinal value to replace last pixel of curRow. Simplifies future end condition checking.    uint32_t realLastPixel = getPixel(curRowPtr, lastPixel);    uint32_t newLastPixel = realLastPixel;    while ((getPixel(curRowPtr, lastPixel-1) == newLastPixel) ||            (getPixel(seedRowPtr, lastPixel) == newLastPixel))    {        putPixel(curRowPtr, lastPixel, newLastPixel += 0x100); // add one to green.    }    unsigned int curPixel = 0;    unsigned int seedRowPixelCopyCount;    unsigned int cachedColor = kWhite;    do // all pixels in row    {        unsigned char CMDByte = 0;        int replacementCount;        // Find seedRowPixelCopyCount for upcoming copy        seedRowPixelCopyCount = curPixel;        while (getPixel(seedRowPtr, curPixel) == getPixel(curRowPtr, curPixel))        {            curPixel++;        }        seedRowPixelCopyCount = curPixel - seedRowPixelCopyCount;        ASSERT (curPixel <= lastPixel);        int pixelSource = 0;        if (curPixel == lastPixel) // On last pixel of row. RLE could also leave us on the last pixel of the row from the previous iteration.        {            putPixel(curRowPtr, lastPixel, realLastPixel);            if (getPixel(seedRowPtr, curPixel) == realLastPixel)            {                goto mode10rtn;            }            else // code last pix as a literal

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -