STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
GUI_SetOrientationCX.h
Go to the documentation of this file.
1 /*********************************************************************
2 * SEGGER Microcontroller GmbH & Co. KG *
3 * Solutions for real time microcontroller applications *
4 **********************************************************************
5 * *
6 * (c) 1996 - 2015 SEGGER Microcontroller GmbH & Co. KG *
7 * *
8 * Internet: www.segger.com Support: support@segger.com *
9 * *
10 **********************************************************************
11 
12 ** emWin V5.28 - Graphical user interface for embedded applications **
13 All Intellectual Property rights in the Software belongs to SEGGER.
14 emWin is protected by international copyright laws. Knowledge of the
15 source code may not be used to write a similar product. This file may
16 only be used in accordance with the following terms:
17 
18 The software has been licensed to STMicroelectronics International
19 N.V. a Dutch company with a Swiss branch and its headquarters in Plan-
20 les-Ouates, Geneva, 39 Chemin du Champ des Filles, Switzerland for the
21 purposes of creating libraries for ARM Cortex-M-based 32-bit microcon_
22 troller products commercialized by Licensee only, sublicensed and dis_
23 tributed under the terms and conditions of the End User License Agree_
24 ment supplied by STMicroelectronics International N.V.
25 Full source code is available at: www.segger.com
26 
27 We appreciate your understanding and fairness.
28 ----------------------------------------------------------------------
29 File : GUI_SetOrientationC0.c
30 Purpose : Runtime display orientation without cache
31 ---------------------------END-OF-HEADER------------------------------
32 */
33 
34 #include "GUI_SetOrientation.h"
35 
36 /*********************************************************************
37 *
38 * Defines
39 *
40 **********************************************************************
41 */
42 #define XY2PTR(x, y) (PIXEL *)(pContext->pData + y * pContext->BytesPerLine + x * pContext->pDrawingAPI->BytesPerPixel)
43 
44 /*********************************************************************
45 *
46 * Static code
47 *
48 **********************************************************************
49 */
50 /*********************************************************************
51 *
52 * Static code
53 *
54 **********************************************************************
55 */
56 /*********************************************************************
57 *
58 * _Sort
59 *
60 * Purpose:
61 * Sorts the values pointed by the given pointers. Please note that
62 * the same static function is also in GUI_SetOrientationC0.h
63 * to enable better compiler optimization.
64 */
65 static void _Sort(int * p0, int * p1) {
66  int temp;
67 
68  if (*p0 > *p1) {
69  temp = *p0;
70  *p0 = *p1;
71  *p1 = temp;
72  }
73 }
74 
75 /*********************************************************************
76 *
77 * Static code: Bitmap drawing routines
78 *
79 **********************************************************************
80 */
81 /*********************************************************************
82 *
83 * Draw Bitmap 1 BPP
84 */
85 static void _DrawBitLine1BPP(GUI_DEVICE * pDevice, unsigned x, unsigned y, U8 const * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
86  LCD_PIXELINDEX IndexMask, Index0, Index1, Pixel;
87  unsigned (* pfGetPixelIndex)(GUI_DEVICE *, int, int);
88  PIXEL * pData;
89  int x_phys, y_phys;
90  DRIVER_CONTEXT * pContext;
91 
92  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
93  Index0 = *(pTrans + 0);
94  Index1 = *(pTrans + 1);
95  x += Diff;
96  pContext->pfLog2Phys(pContext, x, y, &x_phys, &y_phys);
97  pData = XY2PTR(x_phys, y_phys);
99  case 0:
100  do {
101  *pData = (PIXEL)(*p & (0x80 >> Diff)) ? Index1 : Index0;
102  pData += pContext->PixelOffset;
103  if (++Diff == 8) {
104  Diff = 0;
105  p++;
106  }
107  } while (--xsize);
108  break;
109  case LCD_DRAWMODE_TRANS:
110  do {
111  if (*p & (0x80 >> Diff)) {
112  *pData = Index1;
113  }
114  pData += pContext->PixelOffset;
115  if (++Diff == 8) {
116  Diff = 0;
117  p++;
118  }
119  } while (--xsize);
120  break;
122  case LCD_DRAWMODE_XOR:
123  pfGetPixelIndex = pDevice->pDeviceAPI->pfGetPixelIndex;
124  IndexMask = pDevice->pColorConvAPI->pfGetIndexMask();
125  do {
126  if (*p & (0x80 >> Diff)) {
127  Pixel = pfGetPixelIndex(pDevice, x, y);
128  Pixel ^= IndexMask;
129  *pData = Pixel;
130  }
131  pData += pContext->PixelOffset;
132  x++;
133  if (++Diff == 8) {
134  Diff = 0;
135  p++;
136  }
137  } while (--xsize);
138  break;
139  }
140 }
141 
142 /*********************************************************************
143 *
144 * Draw Bitmap 2 BPP
145 */
146 static void _DrawBitLine2BPP(GUI_DEVICE * pDevice, int x, int y, U8 const * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
147  LCD_PIXELINDEX Pixels, PixelIndex;
148  int CurrentPixel, Shift, Index;
149  PIXEL * pData;
150  int x_phys, y_phys;
151  DRIVER_CONTEXT * pContext;
152 
153  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
154  Pixels = *p;
155  CurrentPixel = Diff;
156  x += Diff;
157  pContext->pfLog2Phys(pContext, x, y, &x_phys, &y_phys);
158  pData = XY2PTR(x_phys, y_phys);
160  case 0:
161  if (pTrans) {
162  do {
163  Shift = (3 - CurrentPixel) << 1;
164  Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
165  PixelIndex = *(pTrans + Index);
166  *pData = (PIXEL)PixelIndex;
167  pData += pContext->PixelOffset;
168  if (++CurrentPixel == 4) {
169  CurrentPixel = 0;
170  Pixels = *(++p);
171  }
172  } while (--xsize);
173  } else {
174  do {
175  Shift = (3 - CurrentPixel) << 1;
176  Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
177  *pData = (PIXEL)Index;
178  pData += pContext->PixelOffset;
179  if (++CurrentPixel == 4) {
180  CurrentPixel = 0;
181  Pixels = *(++p);
182  }
183  } while (--xsize);
184  }
185  break;
186  case LCD_DRAWMODE_TRANS:
187  if (pTrans) {
188  do {
189  Shift = (3 - CurrentPixel) << 1;
190  Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
191  if (Index) {
192  PixelIndex = *(pTrans + Index);
193  *pData = (PIXEL)PixelIndex;
194  }
195  pData += pContext->PixelOffset;
196  if (++CurrentPixel == 4) {
197  CurrentPixel = 0;
198  Pixels = *(++p);
199  }
200  } while (--xsize);
201  } else {
202  do {
203  Shift = (3 - CurrentPixel) << 1;
204  Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
205  if (Index) {
206  *pData = (PIXEL)Index;
207  }
208  pData += pContext->PixelOffset;
209  if (++CurrentPixel == 4) {
210  CurrentPixel = 0;
211  Pixels = *(++p);
212  }
213  } while (--xsize);
214  }
215  break;
216  }
217 }
218 
219 /*********************************************************************
220 *
221 * Draw Bitmap 4 BPP
222 */
223 static void _DrawBitLine4BPP(GUI_DEVICE * pDevice, int x, int y, U8 const * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans) {
224  LCD_PIXELINDEX Pixels, PixelIndex;
225  int CurrentPixel, Shift, Index;
226  PIXEL * pData;
227  int x_phys, y_phys;
228  DRIVER_CONTEXT * pContext;
229 
230  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
231  Pixels = *p;
232  CurrentPixel = Diff;
233  x += Diff;
234  pContext->pfLog2Phys(pContext, x, y, &x_phys, &y_phys);
235  pData = XY2PTR(x_phys, y_phys);
237  case 0:
238  if (pTrans) {
239  do {
240  Shift = (1 - CurrentPixel) << 2;
241  Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
242  PixelIndex = *(pTrans + Index);
243  *pData = (PIXEL)PixelIndex;
244  pData += pContext->PixelOffset;
245  if (++CurrentPixel == 2) {
246  CurrentPixel = 0;
247  Pixels = *(++p);
248  }
249  } while (--xsize);
250  } else {
251  do {
252  Shift = (1 - CurrentPixel) << 2;
253  Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
254  *pData = (PIXEL)Index;
255  pData += pContext->PixelOffset;
256  if (++CurrentPixel == 2) {
257  CurrentPixel = 0;
258  Pixels = *(++p);
259  }
260  } while (--xsize);
261  }
262  break;
263  case LCD_DRAWMODE_TRANS:
264  if (pTrans) {
265  do {
266  Shift = (1 - CurrentPixel) << 2;
267  Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
268  if (Index) {
269  PixelIndex = *(pTrans + Index);
270  *pData = (PIXEL)PixelIndex;
271  }
272  pData += pContext->PixelOffset;
273  if (++CurrentPixel == 2) {
274  CurrentPixel = 0;
275  Pixels = *(++p);
276  }
277  } while (--xsize);
278  } else {
279  do {
280  Shift = (1 - CurrentPixel) << 2;
281  Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
282  if (Index) {
283  *pData = (PIXEL)Index;
284  }
285  pData += pContext->PixelOffset;
286  if (++CurrentPixel == 2) {
287  CurrentPixel = 0;
288  Pixels = *(++p);
289  }
290  } while (--xsize);
291  }
292  break;
293  }
294 }
295 
296 /*********************************************************************
297 *
298 * Draw Bitmap 8 BPP
299 */
300 static void _DrawBitLine8BPP(GUI_DEVICE * pDevice, int x, int y, U8 const * p, int xsize, const LCD_PIXELINDEX * pTrans) {
301  LCD_PIXELINDEX Pixel;
302  PIXEL * pData;
303  int x_phys, y_phys;
304  DRIVER_CONTEXT * pContext;
305 
306  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
307  pContext->pfLog2Phys(pContext, x, y, &x_phys, &y_phys);
308  pData = XY2PTR(x_phys, y_phys);
310  case 0:
311  if (pTrans) {
312  do {
313  Pixel = *p++;
314  *pData = (PIXEL)*(pTrans + Pixel);
315  pData += pContext->PixelOffset;
316  } while (--xsize);
317  } else {
318  do {
319  *pData = (PIXEL)*p++;
320  pData += pContext->PixelOffset;
321  } while (--xsize);
322  }
323  break;
324  case LCD_DRAWMODE_TRANS:
325  if (pTrans) {
326  do {
327  Pixel = *p++;
328  if (Pixel) {
329  *pData = (PIXEL)*(pTrans + Pixel);
330  }
331  pData += pContext->PixelOffset;
332  } while (--xsize);
333  } else {
334  do {
335  Pixel = *p++;
336  if (Pixel) {
337  *pData = (PIXEL)Pixel;
338  }
339  pData += pContext->PixelOffset;
340  } while (--xsize);
341  }
342  break;
343  }
344 }
345 
346 /*********************************************************************
347 *
348 * Draw Bitmap 16 BPP
349 */
350 static void _DrawBitLine16BPP(GUI_DEVICE * pDevice, int x, int y, U16 const * p, int xsize) {
351  PIXEL * pData;
352  int x_phys, y_phys, PixelOffset;
353  DRIVER_CONTEXT * pContext;
354 
355  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
356  pContext->pfLog2Phys(pContext, x, y, &x_phys, &y_phys);
357  pData = XY2PTR(x_phys, y_phys);
358  PixelOffset = pContext->PixelOffset;
359  do {
360  *pData = (PIXEL)*p++;
361  pData += PixelOffset;
362  } while (--xsize);
363 }
364 
365 /*********************************************************************
366 *
367 * Draw Bitmap 32 BPP
368 */
369 static void _DrawBitLine32BPP(GUI_DEVICE * pDevice, int x, int y, U32 const * p, int xsize) {
370  PIXEL * pData;
371  int x_phys, y_phys, PixelOffset;
372  DRIVER_CONTEXT * pContext;
373 
374  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
375  pContext->pfLog2Phys(pContext, x, y, &x_phys, &y_phys);
376  pData = XY2PTR(x_phys, y_phys);
377  PixelOffset = pContext->PixelOffset;
378  do {
379  *pData = (PIXEL)*p++;
380  pData += PixelOffset;
381  } while (--xsize);
382 }
383 
384 /*********************************************************************
385 *
386 * Static code: API functions for drawing operations, no cache
387 *
388 **********************************************************************
389 */
390 /*********************************************************************
391 *
392 * _DrawBitmap_CX
393 */
394 static void _DrawBitmap_CX(GUI_DEVICE * pDevice, int x0, int y0,
395  int xSize, int ySize,
396  int BitsPerPixel,
397  int BytesPerLine,
398  const U8 * pData, int Diff,
399  const LCD_PIXELINDEX * pTrans) {
400  int x0_phys, y0_phys, x1_phys, y1_phys;
401  int i;
402  PIXEL * pDataBM;
403  DRIVER_CONTEXT * pContext;
404 
405  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
406  switch (BitsPerPixel) {
407  case 1:
408  for (i = 0; i < ySize; i++) {
409  _DrawBitLine1BPP(pDevice, x0, i + y0, pData, Diff, xSize, pTrans);
410  pData += BytesPerLine;
411  }
412  break;
413  case 2:
414  for (i = 0; i < ySize; i++) {
415  _DrawBitLine2BPP(pDevice, x0, i + y0, pData, Diff, xSize, pTrans);
416  pData += BytesPerLine;
417  }
418  break;
419  case 4:
420  for (i = 0; i < ySize; i++) {
421  _DrawBitLine4BPP(pDevice, x0, i + y0, pData, Diff, xSize, pTrans);
422  pData += BytesPerLine;
423  }
424  break;
425  case 8:
426  for (i = 0; i < ySize; i++) {
427  _DrawBitLine8BPP(pDevice, x0, i + y0, pData, xSize, pTrans);
428  pData += BytesPerLine;
429  }
430  break;
431  case 16:
432  for (i = 0; i < ySize; i++) {
433  _DrawBitLine16BPP(pDevice, x0, i + y0, (U16 *)pData, xSize);
434  pData += BytesPerLine;
435  }
436  break;
437  case 32:
438  for (i = 0; i < ySize; i++) {
439  _DrawBitLine32BPP(pDevice, x0, i + y0, (U32 *)pData, xSize);
440  pData += BytesPerLine;
441  }
442  break;
443  }
444 
445  pContext->pfLog2Phys(pContext, x0 + Diff, y0, &x0_phys, &y0_phys);
446  pContext->pfLog2Phys(pContext, x0 + Diff + xSize - 1, y0 + ySize - 1, &x1_phys, &y1_phys);
447  _Sort(&x0_phys, &x1_phys);
448  _Sort(&y0_phys, &y1_phys);
449  pDataBM = XY2PTR(x0_phys, y0_phys);
450  pDevice = pDevice->pNext;
451  pDevice->pDeviceAPI->pfDrawBitmap(pDevice,
452  x0_phys, y0_phys,
453  x1_phys - x0_phys + 1,
454  y1_phys - y0_phys + 1,
455  pContext->pDrawingAPI->BytesPerPixel << 3,
456  pContext->pDrawingAPI->BytesPerPixel * pContext->vxSize,
457  (U8 *)pDataBM, 0, NULL);
458 }
459 
460 /*********************************************************************
461 *
462 * _GetPixelIndex_CX
463 */
464 static unsigned int _GetPixelIndex_CX(GUI_DEVICE * pDevice, int x, int y) {
465  PIXEL * pData;
466  PIXEL Pixel;
467  int x_phys, y_phys;
468  DRIVER_CONTEXT * pContext;
469 
470  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
471  pContext->pfLog2Phys(pContext, x, y, &x_phys, &y_phys);
472  pData = XY2PTR(x_phys, y_phys);
473  Pixel = *pData;
474  return Pixel;
475 }
476 
477 /*********************************************************************
478 *
479 * _SetPixelIndex_CX
480 */
481 static void _SetPixelIndex_CX(GUI_DEVICE * pDevice, int x, int y, int PixelIndex) {
482  PIXEL * pData;
483  int x_phys, y_phys;
484  DRIVER_CONTEXT * pContext;
485 
486  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
487  pContext->pfLog2Phys(pContext, x, y, &x_phys, &y_phys);
488  pData = XY2PTR(x_phys, y_phys);
489  *pData = (PIXEL)PixelIndex;
490  pDevice = pDevice->pNext;
491  pDevice->pDeviceAPI->pfSetPixelIndex(pDevice, x_phys, y_phys, PixelIndex);
492 }
493 
494 /*********************************************************************
495 *
496 * _XorPixel_CX
497 */
498 static void _XorPixel_CX(GUI_DEVICE * pDevice, int x, int y) {
499  PIXEL Pixel, IndexMask;
500 
501  IndexMask = pDevice->pColorConvAPI->pfGetIndexMask();
502  Pixel = pDevice->pDeviceAPI->pfGetPixelIndex(pDevice, x, y);
503  Pixel ^= IndexMask;
504  pDevice->pDeviceAPI->pfSetPixelIndex(pDevice, x, y, Pixel);
505 }
506 
507 /*********************************************************************
508 *
509 * _DrawHLine_CX
510 */
511 static void _DrawHLine_CX(GUI_DEVICE * pDevice, int x0, int y, int x1) {
512  pDevice->pDeviceAPI->pfFillRect(pDevice, x0, y, x1, y);
513 }
514 
515 /*********************************************************************
516 *
517 * _DrawVLine_CX
518 */
519 static void _DrawVLine_CX(GUI_DEVICE * pDevice, int x, int y0, int y1) {
520  pDevice->pDeviceAPI->pfFillRect(pDevice, x, y0, x, y1);
521 }
522 
523 /*********************************************************************
524 *
525 * _FillRect_CX
526 */
527 static void _FillRect_CX(GUI_DEVICE * pDevice, int x0, int y0, int x1, int y1) {
528  PIXEL * pData;
529  PIXEL * pLine;
530  PIXEL * pPixel;
531  PIXEL Pixel, IndexMask;
532  int x0_phys, y0_phys, x1_phys, y1_phys;
533  int NumPixels, NumLines;
534  DRIVER_CONTEXT * pContext;
535 
536  pContext = (DRIVER_CONTEXT *)pDevice->u.pContext;
537  pContext->pfLog2Phys(pContext, x0, y0, &x0_phys, &y0_phys);
538  pContext->pfLog2Phys(pContext, x1, y1, &x1_phys, &y1_phys);
539  _Sort(&x0_phys, &x1_phys);
540  _Sort(&y0_phys, &y1_phys);
541  pData = pLine = XY2PTR(x0_phys, y0_phys);
542  NumLines = y1_phys - y0_phys + 1;
544  IndexMask = pDevice->pColorConvAPI->pfGetIndexMask();
545  do {
546  pPixel = pLine;
547  NumPixels = x1_phys - x0_phys + 1;
548  do {
549  *pPixel++ ^= IndexMask;
550  } while (--NumPixels);
551  pLine += pContext->vxSize;
552  } while (--NumLines);
553  } else {
554  Pixel = (PIXEL)LCD__GetColorIndex();
555  if (sizeof(Pixel) == 1) {
556  NumPixels = x1_phys - x0_phys + 1;
557  do {
558  GUI_MEMSET((U8 *)pLine, Pixel, NumPixels);
559  pLine += pContext->vxSize;
560  } while (--NumLines);
561  } else {
562  do {
563  pPixel = pLine;
564  NumPixels = x1_phys - x0_phys + 1;
565  do {
566  *pPixel++ = Pixel;
567  } while (--NumPixels);
568  pLine += pContext->vxSize;
569  } while (--NumLines);
570  }
571  }
572  pDevice = pDevice->pNext;
573  pDevice->pDeviceAPI->pfDrawBitmap(pDevice,
574  x0_phys, y0_phys,
575  x1_phys - x0_phys + 1,
576  y1_phys - y0_phys + 1,
577  pContext->pDrawingAPI->BytesPerPixel << 3,
578  pContext->pDrawingAPI->BytesPerPixel * pContext->vxSize,
579  (U8 *)pData, 0, NULL);
580 }
581 
582 /*********************************************************************
583 *
584 * Static data: Drawing API(s)
585 *
586 **********************************************************************
587 */
588 /*********************************************************************
589 *
590 * GUI_OrientationAPI_CX
591 */
593  _DrawBitmap_CX,
594  _DrawHLine_CX,
595  _DrawVLine_CX,
596  _FillRect_CX,
597  _GetPixelIndex_CX,
598  _SetPixelIndex_CX,
599  _XorPixel_CX,
600  BYTES_PER_PIXEL
601 };
602 
603 /*************************** End of file ****************************/
GUI_SADDR GUI_CONTEXT * GUI_pContext
#define LCD__GetColorIndex()
Definition: GUI_Private.h:588
tLCDDEV_GetIndexMask * pfGetIndexMask
Definition: LCD.h:139
#define GUI_MEMSET
#define U32
Definition: Global.h:50
void(* pfSetPixelIndex)(GUI_DEVICE *pDevice, int x, int y, int ColorIndex)
Definition: GUI.h:106
#define LCD_PIXELINDEX
union GUI_DEVICE::@32 u
#define XY2PTR(x, y)
const GUI_ORIENTATION_API * pDrawingAPI
void * pContext
Definition: GUI.h:179
void(* pfDrawBitmap)(GUI_DEVICE *pDevice, int x0, int y0, int xsize, int ysize, int BitsPerPixel, int BytesPerLine, const U8 *pData, int Diff, const LCD_PIXELINDEX *pTrans)
Definition: GUI.h:101
#define NULL
Definition: usbd_def.h:53
U8 DrawMode
Definition: GUI.h:214
#define LCD_DRAWMODE_TRANS
Definition: LCD.h:87
#define LCD_DRAWMODE_XOR
Definition: LCD.h:86
void(* pfFillRect)(GUI_DEVICE *pDevice, int x0, int y0, int x1, int y1)
Definition: GUI.h:104
const LCD_API_COLOR_CONV * pColorConvAPI
Definition: GUI.h:185
const GUI_ORIENTATION_API API_NAME
void(* pfLog2Phys)(DRIVER_CONTEXT *pContext, int x, int y, int *px_phys, int *py_phys)
GUI_DEVICE * pNext
Definition: GUI.h:172
#define U16
Definition: Global.h:47
const GUI_DEVICE_API * pDeviceAPI
Definition: GUI.h:184
#define U8
Definition: Global.h:44
unsigned(* pfGetPixelIndex)(GUI_DEVICE *pDevice, int x, int y)
Definition: GUI.h:105