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

📄 drawline.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        for (i = 0; i < xDelta - 1; ++i)        {            if ((errorTerm += adjUp) > 0)            {                errorTerm -= adjDown;                for (j = 0; j < wholeStep + 1; ++j)                {                   if( !bBlended )                      *p = color;                   else                      BLURALPHA(*p, color);                   p += width;                }            }            else            {                for (j = 0; j < wholeStep; ++j)                {                   if( !bBlended )                      *p = color;                   else                      BLURALPHA(*p, color);                   p += width;                }            }            p += xAdvance;        }        for (j = 0; j < finalPixelCount; ++j)        {           if( !bBlended )              *p = color;           else              BLURALPHA(*p, color);           p += width;        }        return;    }}BOOL DrawOffColor(INT32 *pPattern,                  INT32 nEntries,                  INT32 nPixelsInPattern,                  UINT32 nPixelCount){    BOOL bRet = FALSE;    INT32 nMod = nPixelCount % nPixelsInPattern;    INT32 nPixelSum = 0;    for (int i=0; i<nEntries; i++)    {        nPixelSum += pPattern[i];        if (nPixelSum > nMod)        {            bRet = i % 2;            break;        }    }    return bRet;}void WriteBits(UCHAR *pBuffer, UINT8 bpp, UINT8 red, UINT8 green, UINT8 blue){    if (bpp == 32)    {        pBuffer[0] = blue;        pBuffer[1] = green;        pBuffer[2] = red;        pBuffer[3] = 0;    }    else if (bpp == 24)    {        pBuffer[0] = blue;        pBuffer[1] = green;        pBuffer[2] = red;    }    // Use most significant bits when "dithering" to RGB565    else if (bpp == 16)    {        pBuffer[0] = 0;        pBuffer[1] = 0;        pBuffer[0] |= blue & 0xF8;        pBuffer[0] |= red>>5;        pBuffer[1] |= (red & 0x1C)<<3;        pBuffer[1] |= green>>3;    }    // Use most significant bits when "dithering" to RGB555 (NEED TO TEST!!!)    else if (bpp == 15)    {        pBuffer[0] = 0;        pBuffer[1] = 0;        pBuffer[0] |= blue & 0xF8;        pBuffer[0] |= red>>5;        pBuffer[1] |= (red & 0x18)<<3;        pBuffer[1] |= (green & 0xF8)>>3;    }}void StraightLine(void *pImage,                  INT32 nPitch,                  INT32 bpp,                  INT32 nImageWidth, INT32 nImageHeight,                  INT32 x0, INT32 y0,                  INT32 x1, INT32 y1,                  UINT8 lineWidth,                  PixelProps *pPrimaryPixels,                  PixelProps *pSecondaryPixels,                  INT32 ulLineSytle,                  INT32 *pCustomPattern, INT32 nCustomEntries){    // Assume image is alwas draw top-down - cross platform??? yikes    if (nPitch < 0)        nPitch *= -1;    UINT8 *pBuffer = (UINT8*)pImage;    INT32 aPattern[2];    PixelProps *pColor = pPrimaryPixels;    if (ulLineSytle != CUSTOM_LINE)    {        // Build our own custom pattern list        if (ulLineSytle == SOLID_LINE)        {            aPattern[0] = 2;            aPattern[1] = 0;        }        else if (ulLineSytle == DOTTED_LINE)        {            aPattern[0] = 2;            aPattern[1] = 2;        }        else if (ulLineSytle == DASHED_LINE)        {            aPattern[0] = 16;            aPattern[1] = 8;        }        pCustomPattern = aPattern;        nCustomEntries = 2;    }    INT32 nPatternPixelSum = 0;    for (int i=0; i<nCustomEntries; i++)        nPatternPixelSum += pCustomPattern[i];            INT32 x0orig = x0;    INT32 y0orig = y0;    INT32 x1orig = x1;    INT32 y1orig = y1;    // Draw a line for each pixel width    for (int j=0; j<lineWidth; j++)    {                INT32 nPixelCount = 0;        // Line length for x and y line components        INT32 yDelta = y1 - y0;        INT32 xDelta = x1 - x0;            // Bytes to move for the next xy pixel        INT32 nNextXPixel = bpp>>3,              nNextYPixel = nPitch;            // Handle negative xy deltas        if (yDelta < 0)        {             yDelta = -yDelta;            nNextYPixel = -nNextYPixel;        }            if (xDelta < 0)        {            xDelta = -xDelta;            nNextXPixel = -nNextXPixel;        }        // Move x and y points to their corresponding byte offset in the image        y0 *= nPitch;        y1 *= nPitch;        x0 *= abs(nNextXPixel);        x1 *= abs(nNextXPixel);        pColor = pPrimaryPixels;        // Write the first pixel in the line        if (DrawOffColor(pCustomPattern,                         nCustomEntries,                         nPatternPixelSum,                         nPixelCount))        {            pColor = pSecondaryPixels;        }                if (pColor->bHasColors)        {            WriteBits(&pBuffer[x0+y0], (UINT8)bpp,                       pColor->red,                      pColor->green,                      pColor->blue);        }        ++nPixelCount;        if (xDelta > yDelta)        {            // Slope more horizontal, so incrment the x value by 1 and             // calculate a new y value.            float slope = (float)(yDelta / xDelta * nNextYPixel);            float newY = (float)(.5 + slope + y0);                    // Set points for next line            ++y0orig;            ++y1orig;                    while (x0 != x1)            {                x0 += nNextXPixel;                newY += slope;                            pColor = pPrimaryPixels;                if (DrawOffColor(pCustomPattern,                                 nCustomEntries,                                 nPatternPixelSum,                                 nPixelCount))                {                    pColor = pSecondaryPixels;                }                        if (pColor->bHasColors)                {                    WriteBits(&pBuffer[x0+(INT32)newY], (UINT8)bpp,                               pColor->red,                              pColor->green,                              pColor->blue);                }                            ++nPixelCount;            }        }        else        {            // Slope more vertical, so incrment the y value by 1 and             // calculate a new x value.            float slope = (float)(xDelta / yDelta * nNextXPixel);            float newX = (float)(.5 + slope + x0);            // Set points for next line            ++x0orig;            ++x1orig;                    while (y0 != y1)            {                y0 += nNextYPixel;                newX += slope;                pColor = pPrimaryPixels;                if (DrawOffColor(pCustomPattern,                                 nCustomEntries,                                 nPatternPixelSum,                                 nPixelCount))                {                    pColor = pSecondaryPixels;                }                        if (pColor->bHasColors)                {                    WriteBits(&pBuffer[(INT32)newX+y0], (UINT8)bpp,                               pColor->red,                              pColor->green,                              pColor->blue);                }                            ++nPixelCount;            }        }        // Reset points to pixels instead of byte offsets        x0 = x0orig;        x1 = x1orig;        y0 = y0orig;        y1 = y1orig;    }}

⌨️ 快捷键说明

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