00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __PNGU__
00013 #define __PNGU__
00014
00015
00016 #define PNGU_OK 0
00017 #define PNGU_ODD_WIDTH 1
00018 #define PNGU_ODD_STRIDE 2
00019 #define PNGU_INVALID_WIDTH_OR_HEIGHT 3
00020 #define PNGU_FILE_IS_NOT_PNG 4
00021 #define PNGU_UNSUPPORTED_COLOR_TYPE 5
00022 #define PNGU_NO_FILE_SELECTED 6
00023 #define PNGU_CANT_OPEN_FILE 7
00024 #define PNGU_CANT_READ_FILE 8
00025 #define PNGU_LIB_ERROR 9
00026
00027
00028 #define PNGU_COLOR_TYPE_GRAY 1
00029 #define PNGU_COLOR_TYPE_GRAY_ALPHA 2
00030 #define PNGU_COLOR_TYPE_PALETTE 3
00031 #define PNGU_COLOR_TYPE_RGB 4
00032 #define PNGU_COLOR_TYPE_RGB_ALPHA 5
00033 #define PNGU_COLOR_TYPE_UNKNOWN 6
00034
00035
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039
00040
00041 typedef unsigned char PNGU_u8;
00042 typedef unsigned short PNGU_u16;
00043 typedef unsigned int PNGU_u32;
00044 typedef unsigned long long PNGU_u64;
00045
00046 typedef struct
00047 {
00048 PNGU_u8 r;
00049 PNGU_u8 g;
00050 PNGU_u8 b;
00051 } PNGUCOLOR;
00052
00053 typedef struct
00054 {
00055 PNGU_u32 imgWidth;
00056 PNGU_u32 imgHeight;
00057 PNGU_u32 imgBitDepth;
00058 PNGU_u32 imgColorType;
00059 PNGU_u32 validBckgrnd;
00060 PNGUCOLOR bckgrnd;
00061 PNGU_u32 numTrans;
00062 PNGUCOLOR *trans;
00063 } PNGUPROP;
00064
00065
00066 struct _IMGCTX;
00067 typedef struct _IMGCTX *IMGCTX;
00068
00069
00070
00071
00072
00073
00074
00075 #define PNGU_RGB8_TO_RGB565(r,g,b) ( ((((PNGU_u16) r) & 0xF8U) << 8) | ((((PNGU_u16) g) & 0xFCU) << 3) | (((PNGU_u16) b) >> 3) )
00076
00077
00078 #define PNGU_RGB8_TO_RGB5A3(r,g,b,a) (PNGU_u16) (((a & 0xE0U) == 0xE0U) ? \
00079 (0x8000U | ((((PNGU_u16) r) & 0xF8U) << 7) | ((((PNGU_u16) g) & 0xF8U) << 2) | (((PNGU_u16) b) >> 3)) : \
00080 (((((PNGU_u16) a) & 0xE0U) << 7) | ((((PNGU_u16) r) & 0xF0U) << 4) | (((PNGU_u16) g) & 0xF0U) | ((((PNGU_u16) b) & 0xF0U) >> 4)))
00081
00082
00083 PNGU_u32 PNGU_RGB8_TO_YCbYCr (PNGU_u8 r1, PNGU_u8 g1, PNGU_u8 b1, PNGU_u8 r2, PNGU_u8 g2, PNGU_u8 b2);
00084
00085
00086 void PNGU_YCbYCr_TO_RGB8 (PNGU_u32 ycbycr, PNGU_u8 *r1, PNGU_u8 *g1, PNGU_u8 *b1, PNGU_u8 *r2, PNGU_u8 *g2, PNGU_u8 *b2);
00087
00088
00089
00090
00091
00092
00093
00094 IMGCTX PNGU_SelectImageFromBuffer (const void *buffer);
00095
00096
00097 IMGCTX PNGU_SelectImageFromDevice (const char *filename);
00098
00099
00100 void PNGU_ReleaseImageContext (IMGCTX ctx);
00101
00102
00103
00104
00105
00106
00107
00108 int PNGU_GetImageProperties (IMGCTX ctx, PNGUPROP *fileproperties);
00109
00110
00111
00112
00113
00114
00115
00116
00117 int PNGU_DecodeToYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
00118
00119
00120 #define PNGU_DECODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
00121 \
00122 PNGU_DecodeToYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
00123 (coordX) * 2, (bufferWidth) - (imgWidth))
00124
00125
00126
00127 int PNGU_DecodeToRGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
00128
00129
00130 #define PNGU_DECODE_TO_COORDS_RGB565(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
00131 \
00132 PNGU_DecodeToRGB565 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
00133 (coordX) * 2, (bufferWidth) - (imgWidth))
00134
00135
00136
00137
00138 int PNGU_DecodeToRGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride, PNGU_u8 default_alpha);
00139
00140
00141 #define PNGU_DECODE_TO_COORDS_RGBA8(ctx,coordX,coordY,imgWidth,imgHeight,default_alpha,bufferWidth,bufferHeight,buffer) \
00142 \
00143 PNGU_DecodeToRGBA8 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
00144 (coordX) * 2, (bufferWidth) - (imgWidth), default_alpha)
00145
00146
00147
00148 int PNGU_DecodeTo4x4RGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer);
00149
00150
00151
00152 int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha);
00153
00154
00155
00156 int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha);
00157
00158
00159
00160 int PNGU_EncodeFromYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
00161
00162 int PNGU_EncodeFromRGB (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
00163 int PNGU_EncodeFromGXTexture (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride);
00164
00165
00166 #define PNGU_ENCODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \
00167 \
00168 PNGU_EncodeFromYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \
00169 (coordX) * 2, (bufferWidth) - (imgWidth))
00170
00171 #ifdef __cplusplus
00172 }
00173 #endif
00174
00175 #endif
00176