Enlarge from a buffer to another buffer

Discussion in 'Windows Vista Drivers' started by David, Aug 30, 2007.

  1. David

    David Guest

    Hi All,
    I write function to anlarge from buffer to another buffer, but it have some
    wrong, can anbody help me check code following:

    static float *CreateCoeff(int nLen, int nNewLen, BOOL bShrink)
    {
    int nSum = 0, nSum2;
    int i = 0;
    float *pRes = ExAllocatePool(NonPagedPool, 2 * nLen * sizeof(float));
    float *pCoeff = pRes;
    float fNorm = (bShrink)? (float)nNewLen / nLen : 1;
    int nDenom = (bShrink)? nLen : nNewLen;

    RtlZeroMemory(pRes, 2 * nLen * sizeof(float));
    for(i = 0; i < nLen; i++, pCoeff += 2)
    {
    nSum2 = nSum + nNewLen;
    if(nSum2 > nLen)
    {
    *pCoeff = (float)(nLen - nSum) / nDenom;
    pCoeff[1] = (float)(nSum2 - nLen) / nDenom;
    nSum2 -= nLen;
    }else
    {
    *pCoeff = fNorm;
    if(nSum2 == nLen)
    {
    pCoeff[1] = -1;
    nSum2 = 0;
    }
    }
    nSum = nSum2;
    }
    return pRes;
    }

    #define F_DELTA 0.0001f

    void EnlargeData(BYTE *pInBuff, WORD wWidth, WORD wHeight, BYTE *pOutBuff,
    WORD wNewWidth, WORD wNewHeight)
    {
    BYTE *pLine = pInBuff;
    BYTE *pPix = pLine;
    BYTE *pPixOld, *pUpPix, *pUpPixOld;
    BYTE *pOutLine = pOutBuff;
    BYTE *pOutPix;

    DWORD dwInLn = (3 * wWidth + 3) & ~3;
    DWORD dwOutLn = (3 * wNewWidth + 3) & ~3;

    int x, y, i;
    BOOL bCrossRow, bCrossCol;
    float *pRowCoeff = CreateCoeff(wNewWidth, wWidth, FALSE);
    float *pColCoeff = CreateCoeff(wNewHeight, wHeight, FALSE);
    float fTmp, fPtTmp[3], *pXCoeff;
    float *pYCoeff = pColCoeff;

    y = 0;
    while(y < wHeight)
    {
    bCrossRow = (pYCoeff[1] > F_DELTA);
    x = 0;
    pXCoeff = pRowCoeff;
    pOutPix = pOutLine;
    pOutLine += dwOutLn;
    pUpPix = pLine;
    if(fabs(pYCoeff[1]) > F_DELTA)
    {
    y++;
    pLine += dwInLn;
    pPix = pLine;
    }
    while(x < wWidth)
    {
    bCrossCol = pXCoeff[1] > F_DELTA;
    pUpPixOld = pUpPix;
    pPixOld = pPix;
    if(fabs(pXCoeff[1]) > F_DELTA)
    {
    x++;
    pUpPix += 3;
    pPix += 3;
    }
    fTmp = (*pXCoeff) * (*pYCoeff);
    for(i = 0; i < 3; i++)
    {
    fPtTmp = fTmp * pUpPixOld;
    }
    if(bCrossCol)
    {
    fTmp = pXCoeff[1] * (*pYCoeff);
    for(i = 0; i < 3; i++)
    {
    fPtTmp += fTmp * pUpPix;
    }
    }
    if(bCrossRow)
    {
    fTmp = *pXCoeff * pYCoeff[1];
    for(i = 0; i < 3; i++)
    {
    fPtTmp += fTmp * pPixOld;
    }
    if(bCrossCol)
    {
    fTmp = pXCoeff[1] * pYCoeff[1];
    for(i = 0; i < 3; i++)
    {
    fPtTmp += fTmp * pPix;
    }
    }
    }
    for(i = 0; i < 3; i++, pOutPix++)
    {
    *pOutPix = (BYTE)fPtTmp;
    }
    pXCoeff += 2;
    }
    pYCoeff += 2;
    }
    ExFreePool(pRowCoeff);
    ExFreePool(pColCoeff);
    }

    Thanks very much for help
    David
     
    David, Aug 30, 2007
    #1
    1. Advertisements

  2. what is going wrong? you also need to save/restore floating point state
    using the appropriate APIs before/after using FP math.

    d
     
    Doron Holan [MSFT], Aug 30, 2007
    #2
    1. Advertisements

  3. Am I wrong that such a task is solvable by an integer-only Brezenham's
    code?
     
    Maxim S. Shatskih, Aug 30, 2007
    #3
  4. David

    David Guest

    Thanks for your reply,

    It function i write at kernel mode, when i debug then it crash, i do not
    know why.

    David,

     
    David, Aug 31, 2007
    #4
  5. David

    David Guest

    Thanks for your reply,

    It function i write at kernel mode, when i debug then it crash, i do not
    know why.
    I doubt this code:

    float *pRes = ExAllocatePool(NonPagedPool, 2 * nLen * sizeof(float));

    in C++ it is : float *pRes = new float[2 * nLen]; how to solve this
    problem?

    David,

     
    David, Aug 31, 2007
    #5
  6. David

    Tim Roberts Guest

    No, there's nothing wrong with that. The problem must be elsewhere.
     
    Tim Roberts, Sep 2, 2007
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.