put a pixel, given its RGBA16 color, into image of any color 16-bitdepth type*/
| 3194 | |
| 3195 | /*put a pixel, given its RGBA16 color, into image of any color 16-bitdepth type*/ |
| 3196 | static void rgba16ToPixel(unsigned char* out, size_t i, |
| 3197 | const LodePNGColorMode* mode, |
| 3198 | unsigned short r, unsigned short g, unsigned short b, unsigned short a) { |
| 3199 | if(mode->colortype == LCT_GREY) { |
| 3200 | unsigned short gray = r; /*((unsigned)r + g + b) / 3u;*/ |
| 3201 | out[i * 2 + 0] = (gray >> 8) & 255; |
| 3202 | out[i * 2 + 1] = gray & 255; |
| 3203 | } else if(mode->colortype == LCT_RGB) { |
| 3204 | out[i * 6 + 0] = (r >> 8) & 255; |
| 3205 | out[i * 6 + 1] = r & 255; |
| 3206 | out[i * 6 + 2] = (g >> 8) & 255; |
| 3207 | out[i * 6 + 3] = g & 255; |
| 3208 | out[i * 6 + 4] = (b >> 8) & 255; |
| 3209 | out[i * 6 + 5] = b & 255; |
| 3210 | } else if(mode->colortype == LCT_GREY_ALPHA) { |
| 3211 | unsigned short gray = r; /*((unsigned)r + g + b) / 3u;*/ |
| 3212 | out[i * 4 + 0] = (gray >> 8) & 255; |
| 3213 | out[i * 4 + 1] = gray & 255; |
| 3214 | out[i * 4 + 2] = (a >> 8) & 255; |
| 3215 | out[i * 4 + 3] = a & 255; |
| 3216 | } else if(mode->colortype == LCT_RGBA) { |
| 3217 | out[i * 8 + 0] = (r >> 8) & 255; |
| 3218 | out[i * 8 + 1] = r & 255; |
| 3219 | out[i * 8 + 2] = (g >> 8) & 255; |
| 3220 | out[i * 8 + 3] = g & 255; |
| 3221 | out[i * 8 + 4] = (b >> 8) & 255; |
| 3222 | out[i * 8 + 5] = b & 255; |
| 3223 | out[i * 8 + 6] = (a >> 8) & 255; |
| 3224 | out[i * 8 + 7] = a & 255; |
| 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | /*Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type.*/ |
| 3229 | static void getPixelColorRGBA8(unsigned char* r, unsigned char* g, |