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

📄 jpgwidget.c

📁 基于TI公司Cortex-M3的uart超级通信开发
💻 C
📖 第 1 页 / 共 3 页
字号:
                bChanged = JPEGWidgetHandlePtrPos(pJPEG, lX, lY);

                //
                // Repaint the widget.
                //
                WidgetPaint(pWidget);
                break;
            }

            //
            // The pointer position has changed.
            //
            case WIDGET_MSG_PTR_MOVE:
            {
                //
                // Calculate the new image offsets based on the new pointer
                // position.
                //
                bChanged = JPEGWidgetHandlePtrPos(pJPEG, lX, lY);

                //
                // If something changed and we were asked to redraw
                // automatically on scrolling, do so here.
                //
                if(bChanged && (pJPEG->ulStyle & JW_STYLE_SCROLL))
                {
                    WidgetPaint(pWidget);
                }
                break;
            }

            default:
                break;
        }
    }

    //
    // Tell the widget manager whether this event occurred within the bounds
    // of this widget.
    //
    return((long)bWithinWidget);
}

//*****************************************************************************
//
//! Handles messages for a JPEG widget.
//!
//! \param pWidget is a pointer to the JPEG widget.
//! \param ulMsg is the message.
//! \param ulParam1 is the first parameter to the message.
//! \param ulParam2 is the second parameter to the message.
//!
//! This function receives messages intended for this JPEG widget and
//! processes them accordingly.  The processing of the message varies based on
//! the message in question.
//!
//! Unrecognized messages are handled by calling WidgetDefaultMsgProc().
//!
//! \return Returns a value appropriate to the supplied message.
//
//*****************************************************************************
long
JPEGWidgetMsgProc(tWidget *pWidget, unsigned long ulMsg,
                  unsigned long ulParam1, unsigned long ulParam2)
{
    //
    // Check the arguments.
    //
    ASSERT(pWidget);

    //
    // Determine which message is being sent.
    //
    switch(ulMsg)
    {
        //
        // The widget paint request has been sent.
        //
        case WIDGET_MSG_PAINT:
        {
            //
            // Handle the widget paint request.
            //
            JPEGWidgetPaint(pWidget);

            //
            // Return one to indicate that the message was successfully
            // processed.
            //
            return(1);
        }

        //
        // One of the pointer requests has been sent.
        //
        case WIDGET_MSG_PTR_DOWN:
        case WIDGET_MSG_PTR_MOVE:
        case WIDGET_MSG_PTR_UP:
        {
            //
            // Handle the pointer request, returning the appropriate value.
            //
            return(JPEGWidgetClick(pWidget, ulMsg, ulParam1, ulParam2));
        }

        //
        // An unknown request has been sent.
        //
        default:
        {
            //
            // Let the default message handler process this message.
            //
            return(WidgetDefaultMsgProc(pWidget, ulMsg, ulParam1, ulParam2));
        }
    }
}

//*****************************************************************************
//
//! Initializes a JPEG widget.
//!
//! \param pWidget is a pointer to the JPEG widget to initialize.
//! \param pDisplay is a pointer to the display on which to draw the push
//! button.
//! \param lX is the X coordinate of the upper left corner of the JPEG widget.
//! \param lY is the Y coordinate of the upper left corner of the JPEG widget.
//! \param lWidth is the width of the JPEG widget.
//! \param lHeight is the height of the JPEG widget.
//!
//! This function initializes the provided JPEG widget.  The widget position
//! is set and all styles and parameters set to 0.  The caller must make use
//! of the various widget functions to set any required parameters after
//! making this call.
//!
//! \return None.
//
//*****************************************************************************
void
JPEGWidgetInit(tJPEGWidget *pWidget, const tDisplay *pDisplay,
               long lX, long lY, long lWidth, long lHeight)
{
    unsigned long ulIdx;

    //
    // Check the arguments.
    //
    ASSERT(pWidget);
    ASSERT(pDisplay);

    //
    // Clear out the widget structure.
    //
    for(ulIdx = 0; ulIdx < sizeof(tJPEGWidget); ulIdx += 4)
    {
        ((unsigned long *)pWidget)[ulIdx / 4] = 0;
    }

    //
    // Set the size of the JPEG widget structure.
    //
    pWidget->sBase.lSize = sizeof(tJPEGWidget);

    //
    // Mark this widget as fully disconnected.
    //
    pWidget->sBase.pParent = 0;
    pWidget->sBase.pNext = 0;
    pWidget->sBase.pChild = 0;

    //
    // Save the display pointer.
    //
    pWidget->sBase.pDisplay = pDisplay;

    //
    // Set the extents of this rectangular JPEG widget.
    //
    pWidget->sBase.sPosition.sXMin = lX;
    pWidget->sBase.sPosition.sYMin = lY;
    pWidget->sBase.sPosition.sXMax = lX + lWidth - 1;
    pWidget->sBase.sPosition.sYMax = lY + lHeight - 1;

    //
    // Use the JPEG widget message handler to process messages to
    // this JPEG widget.
    //
    pWidget->sBase.pfnMsgProc = JPEGWidgetMsgProc;
}

//*****************************************************************************
//
//! Pass a new compressed image to the widget.
//!
//! \param pWidget is a pointer to the JPEG widget whose image is to be
//! set.
//! \param pImg is a pointer to the compressed JPEG data for the image.
//! \param ulImgLen is the number of bytes of data pointed to by pImg.
//!
//! This function is used to change the image displayed by a JPEG widget.  It is
//! safe to call it when the widget is already displaying an image since it
//! will free any existing image before decompressing the new one.  The client
//! is responsible for repainting the widget after this call is made.
//!
//! \return Returns 0 on success. Any other return code indicates failure.
//
//*****************************************************************************
long
JPEGWidgetImageSet(tWidget *pWidget, const unsigned char *pImg,
                   unsigned long ulImgLen)
{
    tJPEGWidget *pJPEG;

    //
    // Check the arguments.
    //
    ASSERT(pWidget);
    ASSERT(pImg);
    ASSERT(ulImgLen);

    //
    // Convert the generic widget pointer into a JPEG widget pointer.
    //
    pJPEG = (tJPEGWidget *)pWidget;

    //
    // Discard any existing image.
    //
    JPEGWidgetImageDiscard(pWidget);

    //
    // Store the new image information.
    //
    pJPEG->ulImageLen = ulImgLen;
    pJPEG->pucImage = pImg;

    //
    // Decompress the new image.
    //
    return(JPEGDecompressImage(pJPEG));
}

//*****************************************************************************
//
//! Decompresses the image associated with a JPEG widget.
//!
//! \param pWidget is a pointer to the JPEG widget whose image is to be
//! decompressed.
//!
//! This function must be called by the client for any JPEG widget whose
//! compressed data pointer is initialized using the JPEGCanvas, JPEGButton
//! or JPEGWidgetStruct macros.  It decompresses the image and readies it
//! for display.
//!
//! This function must NOT be used if the widget already holds a decompressed
//! image (i.e. if this function has been called before or if a prior call
//! has been made to JPEGWidgetImageSet() without a later call to
//! JPEGWidgetImageDiscard()) since this will result in a serious memory leak.
//!
//! The client is responsible for repainting the widget after this call is
//! made.
//!
//! \return Returns 0 on success. Any other return code indicates failure.
//
//*****************************************************************************
long
JPEGWidgetImageDecompress(tWidget *pWidget)
{
    tJPEGWidget *pJPEG;

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

    //
    // Convert the generic widget pointer into a JPEG widget pointer.
    //
    pJPEG = (tJPEGWidget *)pWidget;

    //
    // Decompress the image.
    //
    return(JPEGDecompressImage(pJPEG));
}

//*****************************************************************************
//
//! Frees any decompressed image held by the widget.
//!
//! \param pWidget is a pointer to the JPEG widget whose image is to be
//! discarded.
//!
//! This function frees any decompressed image that is currently held by the
//! widget and returns the memory it was occupying to the RAM heap.  After
//! this call, JPEGWidgetImageDecompress() may be called to re-decompress the
//! same image or JPEGWidgetImageSet() can be called to have the widget
//! decompress a new image.
//!
//! \return None.
//
//*****************************************************************************
void
JPEGWidgetImageDiscard(tWidget *pWidget)
{
    tJPEGWidget *pJPEG;

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

    //
    // Convert the generic widget pointer into a JPEG widget pointer.
    //
    pJPEG = (tJPEGWidget *)pWidget;

    //
    // Does this widget currently have a decompressed image?
    //
    if(pJPEG->psJPEGInst->pusImage)
    {
        //
        // Yes - free it up and clear all the image sizes back to zero.
        //
        ExtRAMFree(pJPEG->psJPEGInst->pusImage);
        pJPEG->psJPEGInst->pusImage = 0;
        pJPEG->psJPEGInst->usHeight = 0;
        pJPEG->psJPEGInst->usWidth = 0;
    }
}

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************

⌨️ 快捷键说明

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