µGFX  2.9
version 2.9
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.io/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 *)(((gU8 *)(p))+(idx)))
22 #define gdispImageGetByte(type, p, idx, shift) (((type)gdispImageGetVar(gU8, p, idx))<<(shift))
23 #define gdispImageSwap16(w) ((((gU16)(w))>>8)|(((gU16)(w))<<8))
24 #define gdispImageSwap32(dw) ((((gU32)(dw))>>24)|((((gU32)(dw))&0x00FF0000)>>8)\
25  |((((gU32)(dw))&0x0000FF00)<<8)|(((gU32)(dw))<<24))
26 #define gdispImageSwapWords32(dw) ((((gU32)(dw))>>16)|(((gU32)(dw))<<16))
27 #define gdispImageSwapBytes32(dw) (((((gU32)(dw))&0xFF000000)>>8)|((((gU32)(dw))&0x00FF0000)<<8)\
28  |((((gU32)(dw))&0x0000FF00)>>8)|(((gU32)(dw))<<8))
29 
30 /*
31  * Get a gU16/gU32 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(gU16, (p), (idx))
36  #define gdispImageGetLE32(p, idx) gdispImageGetVar(gU32, (p), (idx))
37 #else
38  #define gdispImageGetLE16(p, idx) ( gdispImageGetByte(gU16, (p), (idx) , 0) | gdispImageGetByte(gU16, (p), (idx)+1, 8))
39  #define gdispImageGetLE32(p, idx) ( gdispImageGetByte(gU32, (p), (idx) , 0) | gdispImageGetByte(gU32, (p), (idx)+1, 8)\
40  |gdispImageGetByte(gU32, (p), (idx)+2, 16) | gdispImageGetByte(gU32, (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(gU16, (p), (idx))
44  #define gdispImageGetBE32(p, idx) gdispImageGetVar(gU32, (p), (idx))
45 #else
46  #define gdispImageGetBE16(p, idx) ( gdispImageGetByte(gU16, (p), (idx) , 8) | gdispImageGetByte(gU16, (p), (idx)+1, 0))
47  #define gdispImageGetBE32(p, idx) ( gdispImageGetByte(gU32, (p), (idx) , 24) | gdispImageGetByte(gU32, (p), (idx)+1, 16)\
48  |gdispImageGetByte(gU32, (p), (idx)+2, 8) | gdispImageGetByte(gU32, (p), (idx)+3, 0))
49 #endif
50 
51 /*
52  * Get a gU16/gU32 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(gU16, (p), (idx))
57  #define gdispImageGetAlignedBE16(p, idx) gdispImageGetBE16(p, (idx))
58  #define gdispImageGetAlignedLE32(p, idx) gdispImageGetVar(gU32, (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(gU16, (p), (idx))
63  #define gdispImageGetAlignedLE32(p, idx) gdispImageGetLE32(p, (idx))
64  #define gdispImageGetAlignedBE32(p, idx) gdispImageGetVar(gU32, (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  gU16 gdispImageH16toLE16(gU16 w);
113  gU16 gdispImageH16toBE16(gU16 w);
114  gU32 gdispImageH32toLE32(gU32 dw);
115  gU32 gdispImageH32toBE32(gU32 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 void *gdispImageAlloc(gImage *img, gMemSize sz);
124 void gdispImageFree(gImage *img, void *ptr, gMemSize sz);
125 
126 #if GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_UNKNOWN
127  extern const gU8 gdispImageEndianArray[4];
128 #endif
129 
130 #endif /* _GDISP_IMAGE_SUPPORT_H */
131 /** @} */
132 
The structure for an image.
Definition: gdisp_image.h:59