AnsweredAssumed Answered

How to use swim_put_image function in the code?

Question asked by LPCware Support on Mar 30, 2016

Once you've created a SWIM window, there are several image related SWIM functions for placing image data into a window.

Before you can use those functions, you need to have a 2D array of pixel data in the LCD's native display format for your image. For example, if you are using RGB565 color (and SWIM should be configured for RGB565 color) and you have a 320x240 pixel image you want to display, you need to provide a pointer to that image data that is at 320x240@RGB565. If you have a BMP image, you can use the BMP to C converter to convert a BMP image to C code in the native display format. You can compile this image data directly into your code.

Once you have the image data and the dimensions of the image, you can use one of the 4 SWIM functions below to display it. If you use a scaled function, the image will be scaled to the window size regardless of it's dimensions. Scaling usually requires adding or removing pixels to get the image to fit in the window. The non-scaled options will clip one or more sides of the image to fit inside the window. For the non-scaled option, an image smaller than the window will not alter window data outside its image. Finally, the SWIM functions also allow you to rotate an image in the window at 90, 180, and 270 degrees.

Example:

An image stored in RGB565 color format is stored in memory pointed to by the variable 'imagedata'. The image is 400x300 pixels in size.

A window with size 640x480 has been created and is pointed to by the win1 variable.

To display the image in the full window scaled to the windows size, use the following function:

   swim_put_scale_image(&win1, imagedata, 400, 300);

SWIM functions:

/* Image rotation tags */ 
typedef enum {NOROTATION, RIGHT, INVERT, LEFT} SWIM_ROTATION_T;

/***********************************************************************
* Image drawing functions
**********************************************************************/ 

/* Puts a raw image into a window */
void swim_put_image(SWIM_WINDOW_T *win,
                    const COLOR_T *image,
                    INT_32 xsize,
                    INT_32 ysize); 

/* Puts a raw image into a window inverted */
void swim_put_invert_image(SWIM_WINDOW_T *win,
                           const COLOR_T *image,
                           INT_32 xsize,
                           INT_32 ysize); 

/* Puts a raw image into a window rotated left */
void swim_put_left_image(SWIM_WINDOW_T *win,
                         const COLOR_T *image,
                         INT_32 xsize,
                         INT_32 ysize); 

/* Puts a raw image into a window rotated right */
void swim_put_right_image(SWIM_WINDOW_T *win,
                          const COLOR_T *image,
                          INT_32 xsize,
                          INT_32 ysize); 

/* Puts and scales a raw image into a window */
void swim_put_scale_image(SWIM_WINDOW_T *win,
                          const COLOR_T *image,
                          INT_32 xsize,
                          INT_32 ysize); 

/* Puts and scales a raw image into a window inverted */
void swim_put_scale_invert_image(SWIM_WINDOW_T *win,
                                 const COLOR_T *image,
                                 INT_32 xsize,
                                 INT_32 ysize); 

/* Puts and scales a raw image into a window rotated left */
void swim_put_scale_left_image(SWIM_WINDOW_T *win,
                               const COLOR_T *image,
                               INT_32 xsize,
                               INT_32 ysize); 

/* Puts and scales a raw image into a window rotated right */
void swim_put_scale_right_image(SWIM_WINDOW_T *win,
                                const COLOR_T *image,
                                INT_32 xsize,
                                INT_32 ysize); 

/* One API for all the functions */
void swim_put_win_image(SWIM_WINDOW_T *win,
                        const COLOR_T *image,
                        INT_32 xsize,
                        INT_32 ysize, INT_32 scale,
                        SWIM_ROTATION_T rtype);

Original Attachment has been moved to: lpcbmp2c.zip

Outcomes