LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
lpc_swim_image.c
Go to the documentation of this file.
1 /*
2  * @brief SWIM image management
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products. This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights. NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers. This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #include "lpc_types.h"
33 #include "lpc_swim_image.h"
34 
35 /*****************************************************************************
36  * Private types/enumerations/variables
37  ****************************************************************************/
38 
39 /*****************************************************************************
40  * Public types/enumerations/variables
41  ****************************************************************************/
42 
43 /*****************************************************************************
44  * Private functions
45  ****************************************************************************/
46 
47 /*****************************************************************************
48  * Public functions
49  ****************************************************************************/
50 
51 /* Puts a raw image into a window */
53  const COLOR_T *image,
54  int32_t xsize,
55  int32_t ysize)
56 {
57  COLOR_T *fb;
58  int32_t x, y;
59 
60  /* Unknown values of rtype will do no rotation */
61  y = win->ypvmin;
62 
63  xsize = xsize + win->xpvmin;
64  ysize = ysize + win->ypvmin;
65 
66  /* Move image to window pixel by pixel */
67  while ((y <= win->ypvmax) && (y < ysize)) {
68  /* Set physical frame buffer address */
69  x = win->xpvmin;
70  fb = win->fb + x + (y * win->xpsize);
71 
72  /* Render a single line */
73  while ((x <= win->xpvmax) && (x < xsize)) {
74  *fb = *image;
75  fb++;
76  image++;
77  x++;
78  }
79 
80  /* Adjust to end of line if the image was clipped */
81  image = image + (xsize - x);
82 
83  y++;
84  }
85 }
86 
87 /* Puts a raw image into a window inverted */
89  const COLOR_T *image,
90  int32_t xsize,
91  int32_t ysize)
92 {
93  COLOR_T *fb;
94  int32_t x, y, xr, yr;
95 
96  y = win->ypvmin;
97  yr = ysize - 1;
98 
99  /* Move image to window pixel by pixel */
100  while ((y <= win->ypvmax) && (yr >= 0)) {
101  /* Set physical frame buffer address */
102  x = win->xpvmin;
103  xr = xsize - 1;
104  fb = win->fb + x + (y * win->xpsize);
105 
106  /* Render a single line */
107  while ((x <= win->xpvmax) && (xr >= 0)) {
108  *fb = image[xr + yr * xsize];
109  fb++;
110  x++;
111  xr--;
112  }
113 
114  y++;
115  yr--;
116  }
117 }
118 
119 /* Puts a raw image into a window rotated left */
121  const COLOR_T *image,
122  int32_t xsize,
123  int32_t ysize)
124 {
125  COLOR_T *fb;
126  int32_t x, y, xr, yr;
127 
128  x = win->xpvmin;
129  yr = ysize - 1;
130 
131  /* Move image to window pixel by pixel */
132  while ((x <= win->xpvmax) && (yr >= 0)) {
133  /* Set physical frame buffer address to start drawing at
134  bottom */
135  y = win->ypvmin;
136  fb = win->fb + x + (y * win->xpsize);
137  xr = 0;
138 
139  /* Render a single line */
140  while ((y <= win->ypvmax) && (xr < xsize)) {
141  /* Go to next line (y) */
142  *fb = image[(xsize - xr - 1) + (ysize - yr - 1) * xsize];
143  fb = fb + win->xpsize;
144 
145  /* Update picture to next x coordinate */
146  y++;
147  xr++;
148  }
149 
150  x++;
151  yr--;
152  }
153 }
154 
155 /* Puts a raw image into a window rotated right */
157  const COLOR_T *image,
158  int32_t xsize,
159  int32_t ysize)
160 {
161  COLOR_T *fb;
162  int32_t x, y, xr, yr;
163 
164  x = win->xpvmin;
165  yr = ysize - 1;
166 
167  /* Move image to window pixel by pixel */
168  while ((x <= win->xpvmax) && (yr >= 0)) {
169  /* Set physical frame buffer address to start drawing at bottom */
170  y = win->ypvmin;
171  fb = win->fb + x + (y * win->xpsize);
172  xr = 0;
173 
174  /* Render a single line */
175  while ((y <= win->ypvmax) && (xr < xsize)) {
176  /* Go to next line (y) */
177  *fb = image[xr + yr * xsize];
178  fb = fb + win->xpsize;
179 
180  /* Update picture to next x coordinate */
181  y++;
182  xr++;
183  }
184 
185  x++;
186  yr--;
187  }
188 }
189 
190 /* Puts and scales a raw image into a window */
192  const COLOR_T *image,
193  int32_t xsize,
194  int32_t ysize)
195 {
196  int32_t xsc, ysc;
197  int32_t x, y;
198  COLOR_T *fb;
199 
200  /* Top of window */
201  y = win->ypvmin;
202 
203  /* Rescale image into window */
204  while (y <= win->ypvmax) {
205  x = win->xpvmin;
206 
207  /* Scale he display size to the image size */
208  ysc = ((ysize - 1) * (y - win->ypvmin)) / win->yvsize;
209  fb = win->fb + x + (y * win->xpsize);
210 
211  /* Render a single line */
212  while (x <= win->xpvmax) {
213  /* Get x pixel in image */
214  xsc = ((xsize - 1) * (x - win->xpvmin)) / win->xvsize;
215  *fb = image[xsc + ysc * xsize];
216  fb++;
217  x++;
218  }
219 
220  y++;
221  }
222 }
223 
224 /* Puts and scales a raw image into a window inverted */
226  const COLOR_T *image,
227  int32_t xsize,
228  int32_t ysize)
229 {
230  int32_t xsc, ysc;
231  int32_t x, y;
232  COLOR_T *fb;
233 
234  /* Top of window */
235  y = win->ypvmin;
236 
237  /* Rescale image into window */
238  while (y <= win->ypvmax) {
239  x = win->xpvmin;
240 
241  /* Scale he display size to the image size */
242  ysc = ((ysize - 1) * (y - win->ypvmin)) / win->yvsize;
243  fb = win->fb + x + (y * win->xpsize);
244 
245  /* Render a single line */
246  while (x <= win->xpvmax) {
247  /* Get x pixel in image */
248  xsc = ((xsize - 1) * (x - win->xpvmin)) / win->xvsize;
249  *fb = image[(xsize - 1 - xsc) + (ysize - 1 - ysc) * xsize];
250  fb++;
251  x++;
252  }
253 
254  y++;
255  }
256 }
257 
258 /* Puts and scales a raw image into a window rotated left */
260  const COLOR_T *image,
261  int32_t xsize,
262  int32_t ysize)
263 {
264  int32_t xsc, ysc;
265  int32_t x, y;
266  COLOR_T *fb;
267 
268  /* Top of window */
269  y = win->ypvmin;
270 
271  /* Rescale image into window */
272  while (y <= win->ypvmax) {
273  x = win->xpvmin;
274 
275  /* Scale y coords of picture into x axis */
276  ysc = ((xsize - 1) * (win->ypvmax - y)) / win->yvsize;
277  fb = win->fb + x + (y * win->xpsize);
278 
279  /* Render a single horizontal line with 'y' data */
280  while (x <= win->xpvmax) {
281  /* Get x pixel in image */
282  xsc = ((ysize - 1) * (x - win->xpvmin)) / win->xvsize;
283  *fb = image[ysc + xsc * xsize];
284  fb++;
285  x++;
286  }
287 
288  y++;
289  }
290 }
291 
292 /* Puts and scales a raw image into a window rotated right */
294  const COLOR_T *image,
295  int32_t xsize,
296  int32_t ysize)
297 {
298  int32_t xsc, ysc;
299  int32_t x, y;
300  COLOR_T *fb;
301 
302  /* Top of window */
303  y = win->ypvmin;
304 
305  /* Rescale image into window */
306  while (y <= win->ypvmax) {
307  x = win->xpvmin;
308 
309  /* Scale y coords of picture into x axis */
310  ysc = ((xsize - 1) * (y - win->ypvmin)) / win->yvsize;
311  fb = win->fb + x + (y * win->xpsize);
312 
313  /* Render a single horizontal line with 'y' data */
314  while (x <= win->xpvmax) {
315  /* Get x pixel in image */
316  xsc = ((ysize - 1) * (win->xpvmax - x)) / win->xvsize;
317  *fb = image[ysc + xsc * xsize];
318  fb++;
319  x++;
320  }
321 
322  y++;
323  }
324 }
325 
326 /* SWIM image draw composite function */
328  const COLOR_T *image,
329  int32_t xsize,
330  int32_t ysize,
331  int32_t scale,
332  SWIM_ROTATION_T rtype)
333 {
334  switch (rtype) {
335  case INVERT:
336  if (scale != 0) {
337  swim_put_scale_invert_image(win, image, xsize, ysize);
338  }
339  else {
340  swim_put_invert_image(win, image, xsize, ysize);
341  }
342  break;
343 
344  case LEFT:
345  if (scale != 0) {
346  swim_put_scale_left_image(win, image, xsize, ysize);
347  }
348  else {
349  swim_put_left_image(win, image, xsize, ysize);
350  }
351  break;
352 
353  case RIGHT:
354  if (scale != 0) {
355  swim_put_scale_right_image(win, image, xsize, ysize);
356  }
357  else {
358  swim_put_right_image(win, image, xsize, ysize);
359  }
360  break;
361 
362  case NOROTATION:
363  default:
364  if (scale != 0) {
365  swim_put_scale_image(win, image, xsize, ysize);
366  }
367  else {
368  swim_put_image(win, image, xsize, ysize);
369  }
370  break;
371  }
372 }