2015-11-11 09:20:10 +00:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms of the GFX License. If a copy of
|
|
|
|
* the license was not distributed with this file, you can obtain one at:
|
|
|
|
*
|
2018-10-01 15:32:39 +00:00
|
|
|
* http://ugfx.io/license.html
|
2015-11-11 09:20:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file src/gdisp/gdisp_image_support.h
|
|
|
|
* @brief GDISP image support routines header file.
|
|
|
|
*
|
|
|
|
* @defgroup Image Image
|
|
|
|
* @ingroup GDISP
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GDISP_IMAGE_SUPPORT_H
|
|
|
|
#define _GDISP_IMAGE_SUPPORT_H
|
|
|
|
|
|
|
|
/* Base endian handling routines */
|
2018-11-03 00:51:23 +00:00
|
|
|
#define gdispImageGetVar(type, p, idx) (*(type *)(((gU8 *)(p))+(idx)))
|
|
|
|
#define gdispImageGetByte(type, p, idx, shift) (((type)gdispImageGetVar(gU8, p, idx))<<(shift))
|
|
|
|
#define gdispImageSwap16(w) ((((gU16)(w))>>8)|(((gU16)(w))<<8))
|
|
|
|
#define gdispImageSwap32(dw) ((((gU32)(dw))>>24)|((((gU32)(dw))&0x00FF0000)>>8)\
|
|
|
|
|((((gU32)(dw))&0x0000FF00)<<8)|(((gU32)(dw))<<24))
|
|
|
|
#define gdispImageSwapWords32(dw) ((((gU32)(dw))>>16)|(((gU32)(dw))<<16))
|
|
|
|
#define gdispImageSwapBytes32(dw) (((((gU32)(dw))&0xFF000000)>>8)|((((gU32)(dw))&0x00FF0000)<<8)\
|
|
|
|
|((((gU32)(dw))&0x0000FF00)>>8)|(((gU32)(dw))<<8))
|
2015-11-11 09:20:10 +00:00
|
|
|
|
|
|
|
/*
|
2018-11-03 00:51:23 +00:00
|
|
|
* Get a gU16/gU32 from memory in the required endianness.
|
2015-11-11 09:20:10 +00:00
|
|
|
* There is no alignment requirement.
|
|
|
|
*/
|
|
|
|
#if GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_LITTLE && GFX_CPU_NO_ALIGNMENT_FAULTS
|
2018-11-03 00:51:23 +00:00
|
|
|
#define gdispImageGetLE16(p, idx) gdispImageGetVar(gU16, (p), (idx))
|
|
|
|
#define gdispImageGetLE32(p, idx) gdispImageGetVar(gU32, (p), (idx))
|
2015-11-11 09:20:10 +00:00
|
|
|
#else
|
2018-11-03 00:51:23 +00:00
|
|
|
#define gdispImageGetLE16(p, idx) ( gdispImageGetByte(gU16, (p), (idx) , 0) | gdispImageGetByte(gU16, (p), (idx)+1, 8))
|
|
|
|
#define gdispImageGetLE32(p, idx) ( gdispImageGetByte(gU32, (p), (idx) , 0) | gdispImageGetByte(gU32, (p), (idx)+1, 8)\
|
|
|
|
|gdispImageGetByte(gU32, (p), (idx)+2, 16) | gdispImageGetByte(gU32, (p), (idx)+3, 24))
|
2015-11-11 09:20:10 +00:00
|
|
|
#endif
|
|
|
|
#if GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_BIG && GFX_CPU_NO_ALIGNMENT_FAULTS
|
2018-11-03 00:51:23 +00:00
|
|
|
#define gdispImageGetBE16(p, idx) gdispImageGetVar(gU16, (p), (idx))
|
|
|
|
#define gdispImageGetBE32(p, idx) gdispImageGetVar(gU32, (p), (idx))
|
2015-11-11 09:20:10 +00:00
|
|
|
#else
|
2018-11-03 00:51:23 +00:00
|
|
|
#define gdispImageGetBE16(p, idx) ( gdispImageGetByte(gU16, (p), (idx) , 8) | gdispImageGetByte(gU16, (p), (idx)+1, 0))
|
|
|
|
#define gdispImageGetBE32(p, idx) ( gdispImageGetByte(gU32, (p), (idx) , 24) | gdispImageGetByte(gU32, (p), (idx)+1, 16)\
|
|
|
|
|gdispImageGetByte(gU32, (p), (idx)+2, 8) | gdispImageGetByte(gU32, (p), (idx)+3, 0))
|
2015-11-11 09:20:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2018-11-03 00:51:23 +00:00
|
|
|
* Get a gU16/gU32 from memory in the required endianness.
|
2015-11-11 09:20:10 +00:00
|
|
|
* These are optimised routines but the memory must be word/dword aligned.
|
|
|
|
*/
|
|
|
|
#if GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_LITTLE
|
2018-11-03 00:51:23 +00:00
|
|
|
#define gdispImageGetAlignedLE16(p, idx) gdispImageGetVar(gU16, (p), (idx))
|
2015-11-17 23:59:31 +00:00
|
|
|
#define gdispImageGetAlignedBE16(p, idx) gdispImageGetBE16(p, (idx))
|
2018-11-03 00:51:23 +00:00
|
|
|
#define gdispImageGetAlignedLE32(p, idx) gdispImageGetVar(gU32, (p), (idx))
|
2015-11-17 23:59:31 +00:00
|
|
|
#define gdispImageGetAlignedBE32(p, idx) gdispImageGetBE32(p, (idx))
|
2015-11-11 09:20:10 +00:00
|
|
|
#elif GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_BIG
|
2015-11-17 23:59:31 +00:00
|
|
|
#define gdispImageGetAlignedLE16(p, idx) gdispImageGetLE16(p, (idx))
|
2018-11-03 00:51:23 +00:00
|
|
|
#define gdispImageGetAlignedBE16(p, idx) gdispImageGetVar(gU16, (p), (idx))
|
2015-11-17 23:59:31 +00:00
|
|
|
#define gdispImageGetAlignedLE32(p, idx) gdispImageGetLE32(p, (idx))
|
2018-11-03 00:51:23 +00:00
|
|
|
#define gdispImageGetAlignedBE32(p, idx) gdispImageGetVar(gU32, (p), (idx))
|
2015-11-11 09:20:10 +00:00
|
|
|
#else
|
2015-11-17 23:59:31 +00:00
|
|
|
#define gdispImageGetAlignedLE16(p, idx) gdispImageGetLE16(p, (idx))
|
|
|
|
#define gdispImageGetAlignedBE16(p, idx) gdispImageGetBE16(p, (idx))
|
|
|
|
#define gdispImageGetAlignedLE32(p, idx) gdispImageGetLE32(p, (idx))
|
|
|
|
#define gdispImageGetAlignedBE32(p, idx) gdispImageGetBE32(p, (idx))
|
2015-11-11 09:20:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change a uint16 or uint32 already in a register to the required endianness.
|
|
|
|
*/
|
|
|
|
#if GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_LITTLE
|
2015-11-12 08:33:12 +00:00
|
|
|
#define gdispImageH16toLE16(w) (w)
|
|
|
|
#define gdispImageH16toBE16(w) gdispImageSwap16(w)
|
|
|
|
#define gdispImageH32toLE32(dw) (dw)
|
|
|
|
#define gdispImageH32toBE32(dw) gdispImageSwap32(dw)
|
2015-11-11 09:20:10 +00:00
|
|
|
#define gdispImageMakeLE16(w)
|
2015-11-12 08:33:12 +00:00
|
|
|
#define gdispImageMakeBE16(w) { w = gdispImageH16toBE16(w); }
|
2015-11-11 09:20:10 +00:00
|
|
|
#define gdispImageMakeLE32(dw)
|
2015-11-12 08:33:12 +00:00
|
|
|
#define gdispImageMakeBE32(dw) { dw = gdispImageH32toBE32(dw); }
|
2015-11-11 09:20:10 +00:00
|
|
|
#elif GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_BIG
|
2015-11-12 08:33:12 +00:00
|
|
|
#define gdispImageH16toLE16(w) gdispImageSwap16(w)
|
|
|
|
#define gdispImageH16toBE16(w) (w)
|
|
|
|
#define gdispImageH32toLE32(dw) gdispImageSwap32(dw)
|
|
|
|
#define gdispImageH32toBE32(dw) (dw)
|
|
|
|
#define gdispImageMakeLE16(w) { w = gdispImageH16toLE16(w); }
|
2015-11-11 09:20:10 +00:00
|
|
|
#define gdispImageMakeBE16(w)
|
2015-11-12 08:33:12 +00:00
|
|
|
#define gdispImageMakeLE32(dw) { dw = gdispImageH32toLE32(dw); }
|
2015-11-11 09:20:10 +00:00
|
|
|
#define gdispImageMakeBE32(dw)
|
2015-11-12 08:33:12 +00:00
|
|
|
#elif GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_WBDWL
|
|
|
|
#define gdispImageH16toLE16(w) gdispImageSwap16(w)
|
|
|
|
#define gdispImageH16toBE16(w) (w)
|
|
|
|
#define gdispImageH32toLE32(dw) gdispImageSwapBytes32(dw)
|
|
|
|
#define gdispImageH32toBE32(dw) gdispImageSwapWords32(dw)
|
|
|
|
#define gdispImageMakeLE16(w) { w = gdispImageH16toLE16(w); }
|
|
|
|
#define gdispImageMakeBE16(w)
|
|
|
|
#define gdispImageMakeLE32(dw) { dw = gdispImageH32toLE32(dw); }
|
|
|
|
#define gdispImageMakeBE32(dw) { dw = gdispImageH32toBE32(dw); }
|
|
|
|
#elif GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_WLDWB
|
|
|
|
#define gdispImageH16toLE16(w) (w)
|
|
|
|
#define gdispImageH16toBE16(w) gdispImageSwap16(w)
|
|
|
|
#define gdispImageH32toLE32(dw) gdispImageSwapWords32(dw)
|
|
|
|
#define gdispImageH32toBE32(dw) gdispImageSwapBytes32(dw)
|
|
|
|
#define gdispImageMakeLE16(w)
|
|
|
|
#define gdispImageMakeBE16(w) { w = gdispImageH16toBE16(w); }
|
|
|
|
#define gdispImageMakeLE32(dw) { dw = gdispImageH32toLE32(dw); }
|
|
|
|
#define gdispImageMakeBE32(dw) { dw = gdispImageH32toBE32(dw); }
|
2015-11-11 09:20:10 +00:00
|
|
|
#else
|
2018-11-03 00:51:23 +00:00
|
|
|
gU16 gdispImageH16toLE16(gU16 w);
|
|
|
|
gU16 gdispImageH16toBE16(gU16 w);
|
|
|
|
gU32 gdispImageH32toLE32(gU32 dw);
|
|
|
|
gU32 gdispImageH32toBE32(gU32 dw);
|
2015-11-12 08:33:12 +00:00
|
|
|
#define gdispImageMakeLE16(w) { w = gdispImageH16toLE16(w); }
|
|
|
|
#define gdispImageMakeBE16(w) { w = gdispImageH16toBE16(w); }
|
|
|
|
#define gdispImageMakeLE32(dw) { dw = gdispImageH32toLE32(dw); }
|
|
|
|
#define gdispImageMakeBE32(dw) { dw = gdispImageH32toBE32(dw); }
|
2015-11-11 09:20:10 +00:00
|
|
|
#endif
|
|
|
|
|
2015-11-12 08:33:12 +00:00
|
|
|
|
2019-04-10 15:33:15 +00:00
|
|
|
void *gdispImageAlloc(gImage *img, gMemSize sz);
|
|
|
|
void gdispImageFree(gImage *img, void *ptr, gMemSize sz);
|
2015-11-11 09:20:10 +00:00
|
|
|
|
2018-06-23 03:02:07 +00:00
|
|
|
#if GFX_CPU_ENDIAN == GFX_CPU_ENDIAN_UNKNOWN
|
2018-11-03 00:51:23 +00:00
|
|
|
extern const gU8 gdispImageEndianArray[4];
|
2015-11-11 09:20:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _GDISP_IMAGE_SUPPORT_H */
|
|
|
|
/** @} */
|
|
|
|
|