put a pixel, given its RGBA16 color, into image of any color 16-bitdepth type*/
| 3219 | |
| 3220 | /*put a pixel, given its RGBA16 color, into image of any color 16-bitdepth type*/ |
| 3221 | static void rgba16ToPixel(unsigned char* out, size_t i, |
| 3222 | const LodePNGColorMode* mode, |
| 3223 | unsigned short r, unsigned short g, unsigned short b, unsigned short a) { |
| 3224 | if(mode->colortype == LCT_GREY) { |
| 3225 | unsigned short gray = r; /*((unsigned)r + g + b) / 3u;*/ |
| 3226 | out[i * 2 + 0] = (gray >> 8) & 255; |
| 3227 | out[i * 2 + 1] = gray & 255; |
| 3228 | } else if(mode->colortype == LCT_RGB) { |
| 3229 | out[i * 6 + 0] = (r >> 8) & 255; |
| 3230 | out[i * 6 + 1] = r & 255; |
| 3231 | out[i * 6 + 2] = (g >> 8) & 255; |
| 3232 | out[i * 6 + 3] = g & 255; |
| 3233 | out[i * 6 + 4] = (b >> 8) & 255; |
| 3234 | out[i * 6 + 5] = b & 255; |
| 3235 | } else if(mode->colortype == LCT_GREY_ALPHA) { |
| 3236 | unsigned short gray = r; /*((unsigned)r + g + b) / 3u;*/ |
| 3237 | out[i * 4 + 0] = (gray >> 8) & 255; |
| 3238 | out[i * 4 + 1] = gray & 255; |
| 3239 | out[i * 4 + 2] = (a >> 8) & 255; |
| 3240 | out[i * 4 + 3] = a & 255; |
| 3241 | } else if(mode->colortype == LCT_RGBA) { |
| 3242 | out[i * 8 + 0] = (r >> 8) & 255; |
| 3243 | out[i * 8 + 1] = r & 255; |
| 3244 | out[i * 8 + 2] = (g >> 8) & 255; |
| 3245 | out[i * 8 + 3] = g & 255; |
| 3246 | out[i * 8 + 4] = (b >> 8) & 255; |
| 3247 | out[i * 8 + 5] = b & 255; |
| 3248 | out[i * 8 + 6] = (a >> 8) & 255; |
| 3249 | out[i * 8 + 7] = a & 255; |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | /*Get RGBA8 color of pixel with index i (y * width + x) from the raw image with given color type.*/ |
| 3254 | static void getPixelColorRGBA8(unsigned char* r, unsigned char* g, |