put a pixel, given its RGBA16 color, into image of any color 16-bitdepth type*/
| 3089 | |
| 3090 | /*put a pixel, given its RGBA16 color, into image of any color 16-bitdepth type*/ |
| 3091 | static void rgba16ToPixel(unsigned char* out, size_t i, |
| 3092 | const LodePNGColorMode* mode, |
| 3093 | unsigned short r, unsigned short g, unsigned short b, unsigned short a) |
| 3094 | { |
| 3095 | if(mode->colortype == LCT_GREY) |
| 3096 | { |
| 3097 | unsigned short grey = r; /*((unsigned)r + g + b) / 3*/; |
| 3098 | out[i * 2 + 0] = (grey >> 8) & 255; |
| 3099 | out[i * 2 + 1] = grey & 255; |
| 3100 | } |
| 3101 | else if(mode->colortype == LCT_RGB) |
| 3102 | { |
| 3103 | out[i * 6 + 0] = (r >> 8) & 255; |
| 3104 | out[i * 6 + 1] = r & 255; |
| 3105 | out[i * 6 + 2] = (g >> 8) & 255; |
| 3106 | out[i * 6 + 3] = g & 255; |
| 3107 | out[i * 6 + 4] = (b >> 8) & 255; |
| 3108 | out[i * 6 + 5] = b & 255; |
| 3109 | } |
| 3110 | else if(mode->colortype == LCT_GREY_ALPHA) |
| 3111 | { |
| 3112 | unsigned short grey = r; /*((unsigned)r + g + b) / 3*/; |
| 3113 | out[i * 4 + 0] = (grey >> 8) & 255; |
| 3114 | out[i * 4 + 1] = grey & 255; |
| 3115 | out[i * 4 + 2] = (a >> 8) & 255; |
| 3116 | out[i * 4 + 3] = a & 255; |
| 3117 | } |
| 3118 | else if(mode->colortype == LCT_RGBA) |
| 3119 | { |
| 3120 | out[i * 8 + 0] = (r >> 8) & 255; |
| 3121 | out[i * 8 + 1] = r & 255; |
| 3122 | out[i * 8 + 2] = (g >> 8) & 255; |
| 3123 | out[i * 8 + 3] = g & 255; |
| 3124 | out[i * 8 + 4] = (b >> 8) & 255; |
| 3125 | out[i * 8 + 5] = b & 255; |
| 3126 | out[i * 8 + 6] = (a >> 8) & 255; |
| 3127 | out[i * 8 + 7] = a & 255; |
| 3128 | } |
| 3129 | } |
| 3130 | |
| 3131 | /*Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type.*/ |
| 3132 | static void getPixelColorRGBA8(unsigned char* r, unsigned char* g, |