version 2.8
gdisp_image_support.h
Go to the documentation of this file.
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.org/license.html
6  */
7 
8 /**
9  * @file src/gdisp/gdisp_image_support.h
10  * @brief GDISP image support routines header file.
11  *
12  * @defgroup Image Image
13  * @ingroup GDISP
14  * @{
15  */
16 
17 #ifndef _GDISP_IMAGE_SUPPORT_H
18 #define _GDISP_IMAGE_SUPPORT_H
19 
20 /* Base endian handling routines */
21 #define gdispImageGetVar(type, p, idx) (*(type *)(((uint8_t *)(p))+(idx)))
22 #define gdispImageGetByte(type, p, idx, shift) (((type)gdispImageGetVar(uint8_t, p, idx))<<(shift))
23 #define gdispImageSwap16(w) ((((uint16_t)(w))>>8)|(((uint16_t)(w))<<8))
24 #define gdispImageSwap32(dw) ((((uint32_t)(dw))>>24)|((((uint32_t)(dw))&0x00FF0000)>>8)\
25  |((((uint32_t)(dw))&0x0000FF00)<<8)|(((uint32_t)(dw))<<24))
26 #define gdispImageSwapWords32(dw) ((((uint32_t)(dw))>>16)|(((uint32_t)(dw))<<16))
27 #define gdispImageSwapBytes32(dw) (((((uint32_t)(dw))&0xFF000000)>>8)|((((uint32_t)(dw))&0x00FF0000)<<8)\
28  |((((uint32_t)(dw))&0x0000FF00)>>8)|(((uint32_t)(dw))<<8))
29 
30 /*
31  * Get a uint16_t/uint32_t from memory in the required endianness.
32  * There is no alignment requirement.
33  */
34 #if GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_LITTLE && GFX_CPU_NO_ALIGNMENT_FAULTS
35  #define gdispImageGetLE16(p, idx) gdispImageGetVar(uint16_t, (p), (idx))
36  #define gdispImageGetLE32(p, idx) gdispImageGetVar(uint32_t, (p), (idx))
37 #else
38  #define gdispImageGetLE16(p, idx) ( gdispImageGetByte(uint16_t, (p), (idx) , 0) | gdispImageGetByte(uint16_t, (p), (idx)+1, 8))
39  #define gdispImageGetLE32(p, idx) ( gdispImageGetByte(uint32_t, (p), (idx) , 0) | gdispImageGetByte(uint32_t, (p), (idx)+1, 8)\
40  |gdispImageGetByte(uint32_t, (p), (idx)+2, 16) | gdispImageGetByte(uint32_t, (p), (idx)+3, 24))
41 #endif
42 #if GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_BIG && GFX_CPU_NO_ALIGNMENT_FAULTS
43  #define gdispImageGetBE16(p, idx) gdispImageGetVar(uint16_t, (p), (idx))
44  #define gdispImageGetBE32(p, idx) gdispImageGetVar(uint32_t, (p), (idx))
45 #else
46  #define gdispImageGetBE16(p, idx) ( gdispImageGetByte(uint16_t, (p), (idx) , 8) | gdispImageGetByte(uint16_t, (p), (idx)+1, 0))
47  #define gdispImageGetBE32(p, idx) ( gdispImageGetByte(uint32_t, (p), (idx) , 24) | gdispImageGetByte(uint32_t, (p), (idx)+1, 16)\
48  |gdispImageGetByte(uint32_t, (p), (idx)+2, 8) | gdispImageGetByte(uint32_t, (p), (idx)+3, 0))
49 #endif
50 
51 /*
52  * Get a uint16_t/uint32_t from memory in the required endianness.
53  * These are optimised routines but the memory must be word/dword aligned.
54  */
55 #if GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_LITTLE
56  #define gdispImageGetAlignedLE16(p, idx) gdispImageGetVar(uint16_t, (p), (idx))
57  #define gdispImageGetAlignedBE16(p, idx) gdispImageGetBE16(p, (idx))
58  #define gdispImageGetAlignedLE32(p, idx) gdispImageGetVar(uint32_t, (p), (idx))
59  #define gdispImageGetAlignedBE32(p, idx) gdispImageGetBE32(p, (idx))
60 #elif GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_BIG
61  #define gdispImageGetAlignedLE16(p, idx) gdispImageGetLE16(p, (idx))
62  #define gdispImageGetAlignedBE16(p, idx) gdispImageGetVar(uint16_t, (p), (idx))
63  #define gdispImageGetAlignedLE32(p, idx) gdispImageGetLE32(p, (idx))
64  #define gdispImageGetAlignedBE32(p, idx) gdispImageGetVar(uint32_t, (p), (idx))
65 #else
66  #define gdispImageGetAlignedLE16(p, idx) gdispImageGetLE16(p, (idx))
67  #define gdispImageGetAlignedBE16(p, idx) gdispImageGetBE16(p, (idx))
68  #define gdispImageGetAlignedLE32(p, idx) gdispImageGetLE32(p, (idx))
69  #define gdispImageGetAlignedBE32(p, idx) gdispImageGetBE32(p, (idx))
70 #endif
71 
72 /*
73  * Change a uint16 or uint32 already in a register to the required endianness.
74  */
75 #if GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_LITTLE
76  #define gdispImageH16toLE16(w) (w)
77  #define gdispImageH16toBE16(w) gdispImageSwap16(w)
78  #define gdispImageH32toLE32(dw) (dw)
79  #define gdispImageH32toBE32(dw) gdispImageSwap32(dw)
80  #define gdispImageMakeLE16(w)
81  #define gdispImageMakeBE16(w) { w = gdispImageH16toBE16(w); }
82  #define gdispImageMakeLE32(dw)
83  #define gdispImageMakeBE32(dw) { dw = gdispImageH32toBE32(dw); }
84 #elif GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_BIG
85  #define gdispImageH16toLE16(w) gdispImageSwap16(w)
86  #define gdispImageH16toBE16(w) (w)
87  #define gdispImageH32toLE32(dw) gdispImageSwap32(dw)
88  #define gdispImageH32toBE32(dw) (dw)
89  #define gdispImageMakeLE16(w) { w = gdispImageH16toLE16(w); }
90  #define gdispImageMakeBE16(w)
91  #define gdispImageMakeLE32(dw) { dw = gdispImageH32toLE32(dw); }
92  #define gdispImageMakeBE32(dw)
93 #elif GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_WBDWL
94  #define gdispImageH16toLE16(w) gdispImageSwap16(w)
95  #define gdispImageH16toBE16(w) (w)
96  #define gdispImageH32toLE32(dw) gdispImageSwapBytes32(dw)
97  #define gdispImageH32toBE32(dw) gdispImageSwapWords32(dw)
98  #define gdispImageMakeLE16(w) { w = gdispImageH16toLE16(w); }
99  #define gdispImageMakeBE16(w)
100  #define gdispImageMakeLE32(dw) { dw = gdispImageH32toLE32(dw); }
101  #define gdispImageMakeBE32(dw) { dw = gdispImageH32toBE32(dw); }
102 #elif GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_WLDWB
103  #define gdispImageH16toLE16(w) (w)
104  #define gdispImageH16toBE16(w) gdispImageSwap16(w)
105  #define gdispImageH32toLE32(dw) gdispImageSwapWords32(dw)
106  #define gdispImageH32toBE32(dw) gdispImageSwapBytes32(dw)
107  #define gdispImageMakeLE16(w)
108  #define gdispImageMakeBE16(w) { w = gdispImageH16toBE16(w); }
109  #define gdispImageMakeLE32(dw) { dw = gdispImageH32toLE32(dw); }
110  #define gdispImageMakeBE32(dw) { dw = gdispImageH32toBE32(dw); }
111 #else
112  uint16_t gdispImageH16toLE16(uint16_t w);
113  uint16_t gdispImageH16toBE16(uint16_t w);
114  uint32_t gdispImageH32toLE32(uint32_t dw);
115  uint32_t gdispImageH32toBE32(uint32_t dw);
116  #define gdispImageMakeLE16(w) { w = gdispImageH16toLE16(w); }
117  #define gdispImageMakeBE16(w) { w = gdispImageH16toBE16(w); }
118  #define gdispImageMakeLE32(dw) { dw = gdispImageH32toLE32(dw); }
119  #define gdispImageMakeBE32(dw) { dw = gdispImageH32toBE32(dw); }
120 #endif
121 
122 
123 #ifdef __cplusplus
124 extern "C" {
125 #endif
126 
127  void *gdispImageAlloc(gdispImage *img, size_t sz);
128  void gdispImageFree(gdispImage *img, void *ptr, size_t sz);
129 
130  #if GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_UNKNOWN
131  extern const uint8_t gdispImageEndianArray[4];
132  #endif
133 
134 #ifdef __cplusplus
135 }
136 #endif
137 
138 #endif /* _GDISP_IMAGE_SUPPORT_H */
139 /** @} */
140 
The structure for an image.
Definition: gdisp_image.h:59