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

📄 offscr4bpp.c

📁 STM32+Grlib
💻 C
📖 第 1 页 / 共 3 页
字号:
                        // Write this pixel to the screen.
                        //
                        *pucPtr = (*pucPtr & ~(0xf << lX)) | (ulByte << lX);
                        if(lX ^= 4)
                        {
                            pucPtr++;
                        }

                        //
                        // Decrement the count of pixels to draw.
                        //
                        lCount--;

                        //
                        // See if there is another pixel to draw.
                        //
                        if(lCount)
                        {
                case 1:
                            //
                            // Get the lower nibble of the next byte of pixel
                            // data and extract the corresponding entry from
                            // the palette.
                            //
                            ulByte = (*pucData++ & 15) * 3;
                            ulByte = (*(unsigned long *)(pucPalette + ulByte) &
                                      0x00ffffff);

                            //
                            // Translate this palette entry.
                            //
                            ulByte =
                                GrOffScreen4BPPColorTranslate(pvDisplayData,
                                                              ulByte);

                            //
                            // Write this pixel to the screen.
                            //
                            *pucPtr = ((*pucPtr & ~(0xf << lX)) |
                                       (ulByte << lX));
                            if(lX ^= 4)
                            {
                                pucPtr++;
                            }

                            //
                            // Decrement the count of pixels to draw.
                            //
                            lCount--;
                        }
                    }
            }

            //
            // The image data has been drawn.
            //
            break;
        }

        //
        // The pixel data is in 8 bit per pixel format.
        //
        case 8:
        {
            //
            // Loop while there are more pixels to draw.
            //
            while(lCount--)
            {
                //
                // Get the next byte of pixel data and extract the
                // corresponding entry from the palette.
                //
                ulByte = *pucData++ * 3;
                ulByte = *(unsigned long *)(pucPalette + ulByte) & 0x00ffffff;

                //
                // Translate this palette entry.
                //
                ulByte = GrOffScreen4BPPColorTranslate(pvDisplayData, ulByte);

                //
                // Write this pixel to the screen.
                //
                *pucPtr = (*pucPtr & ~(0xf << lX)) | (ulByte << lX);
                if(lX ^= 4)
                {
                    pucPtr++;
                }
            }

            //
            // The image data has been drawn.
            //
            break;
        }
    }
}

//*****************************************************************************
//
//! Draws a horizontal line.
//!
//! \param pvDisplayData is a pointer to the driver-specific data for this
//! display driver.
//! \param lX1 is the X coordinate of the start of the line.
//! \param lX2 is the X coordinate of the end of the line.
//! \param lY is the Y coordinate of the line.
//! \param ulValue is the color of the line.
//!
//! This function draws a horizontal line on the display.  The coordinates of
//! the line are assumed to be within the extents of the display.
//!
//! \return None.
//
//*****************************************************************************
static void
GrOffScreen4BPPLineDrawH(void *pvDisplayData, long lX1, long lX2, long lY,
                         unsigned long ulValue)
{
    unsigned char *pucData;
    long lBytesPerRow;

    //
    // Check the arguments.
    //
    ASSERT(pvDisplayData);

    //
    // Create a character pointer for the display-specific data (which points
    // to the image buffer).
    //
    pucData = (unsigned char *)pvDisplayData;

    //
    // Compute the number of bytes per row in the image buffer.
    //
    lBytesPerRow = (*(unsigned short *)(pucData + 1) + 1) / 2;

    //
    // Get the offset to the byte of the image buffer that contains the
    // starting pixel.
    //
    pucData += (lBytesPerRow * lY) + (lX1 / 2) + 6 + (16 * 3);

    //
    // Copy the pixel value into all 8 pixels of the unsigned long.  This will
    // be used later to write multiple pixels into memory (as opposed to one at
    // a time).
    //
    ulValue = ((ulValue << 28) | (ulValue << 24) | (ulValue << 20) |
               (ulValue << 16) | (ulValue << 12) | (ulValue << 8) |
               (ulValue << 4) | ulValue);

    //
    // See if the second pixel in a byte is part of the line.
    //
    if(lX1 & 1)
    {
        //
        // Draw the second pixel in the byte.
        //
        *pucData = (*pucData & 0xf0) | (ulValue & 0x0f);
        pucData++;
        lX1++;
    }

    //
    // See if the buffer pointer is not half-word aligned and there are at
    // least two pixels left to draw.
    //
    if(((unsigned long)pucData & 1) && ((lX2 - lX1) > 0))
    {
        //
        // Draw two pixels to half-word align the buffer pointer.
        //
        *pucData++ = ulValue & 0xff;
        lX1 += 2;
    }

    //
    // See if the buffer pointer is not word aligned and there are at least
    // four pixels left to draw.
    //
    if(((unsigned long)pucData & 2) && ((lX2 - lX1) > 2))
    {
        //
        // Draw four pixels to word align the buffer pointer.
        //
        *(unsigned short *)pucData = ulValue & 0xffff;
        pucData += 2;
        lX1 += 4;
    }

    //
    // Loop while there are at least eight pixels left to draw.
    //
    while((lX1 + 7) <= lX2)
    {
        //
        // Draw eight pixels.
        //
        *(unsigned long *)pucData = ulValue;
        pucData += 4;
        lX1 += 8;
    }

    //
    // See if there are at least four pixels left to draw.
    //
    if((lX1 + 3) <= lX2)
    {
        //
        // Draw four pixels, leaving the buffer pointer half-word aligned.
        //
        *(unsigned short *)pucData = ulValue & 0xffff;
        pucData += 2;
        lX1 += 4;
    }

    //
    // See if there are at least two pixels left to draw.
    //
    if((lX1 + 1) <= lX2)
    {
        //
        // Draw two pixels, leaving the buffer pointer byte aligned.
        //
        *pucData++ = ulValue & 0xff;
        lX1 += 2;
    }

    //
    // See if there is one pixel left to draw.
    //
    if(lX1 == lX2)
    {
        //
        // Draw the final pixel.
        //
        *pucData = (*pucData & 0x0f) | (ulValue & 0xf0);
    }
}

//*****************************************************************************
//
//! Draws a vertical line.
//!
//! \param pvDisplayData is a pointer to the driver-specific data for this
//! display driver.
//! \param lX is the X coordinate of the line.
//! \param lY1 is the Y coordinate of the start of the line.
//! \param lY2 is the Y coordinate of the end of the line.
//! \param ulValue is the color of the line.
//!
//! This function draws a vertical line on the display.  The coordinates of the
//! line are assumed to be within the extents of the display.
//!
//! \return None.
//
//*****************************************************************************
static void
GrOffScreen4BPPLineDrawV(void *pvDisplayData, long lX, long lY1, long lY2,
                         unsigned long ulValue)
{
    unsigned char *pucData;
    long lBytesPerRow;

    //
    // Check the arguments.
    //
    ASSERT(pvDisplayData);

    //
    // Create a character pointer for the display-specific data (which points
    // to the image buffer).
    //
    pucData = (unsigned char *)pvDisplayData;

    //
    // Compute the number of bytes per row in the image buffer.
    //
    lBytesPerRow = (*(unsigned short *)(pucData + 1) + 1) / 2;

    //
    // Get the offset to the byte of the image buffer that contains the
    // starting pixel.
    //
    pucData += (lBytesPerRow * lY1) + (lX / 2) + 6 + (16 * 3);

    //
    // See if the vertical line resides in the first or second nibble.
    //
    if(lX & 1)
    {
        //
        // The line resides in the second nibble.  Loop over the rows of the
        // line.
        //
        while(lY1 <= lY2)
        {
            //
            // Draw this pixel of the line.
            //
            *pucData = (*pucData & 0xf0) | ulValue;
            pucData += lBytesPerRow;
            lY1++;
        }
    }
    else
    {
        //
        // The line resides in the first nibble.  Loop over the rows of the
        // line.
        //
        ulValue <<= 4;
        while(lY1 <= lY2)
        {
            //
            // Draw this pixel of the line.
            //
            *pucData = (*pucData & 0x0f) | ulValue;
            pucData += lBytesPerRow;
            lY1++;
        }
    }
}

⌨️ 快捷键说明

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