#include #include "libimg-internal.h" void img_lighten(img_t src, img_t dst) { if(!img_target(dst, src.width, src.height)) return; img_pixel_t *src_px = src.pixels; img_pixel_t *dst_px = dst.pixels; for(int y = 0; y < src.height; y++) { for(int x = 0; x < src.width; x++) { if(src_px[x] == IMG_ALPHA) continue; int dbl = src_px[x] << 1; int carry = dbl & 0x10820; carry = ((carry << 5) - carry) >> 5; dst_px[x] = carry | (dbl & 0xffff) | 0x0841; } src_px += src.stride; dst_px += dst.stride; } } img_t img_lighten_create(img_t src) { img_t dst = img_create(src.width, src.height); img_fill(dst, IMG_ALPHA); img_lighten(src, dst); return dst; } void img_whiten(img_t src, img_t dst) { if(!img_target(dst, src.width, src.height)) return; img_pixel_t *src_px = src.pixels; img_pixel_t *dst_px = dst.pixels; for(int y = 0; y < src.height; y++) { for(int x = 0; x < src.width; x++) { if(src_px[x] == IMG_ALPHA) continue; dst_px[x] = ~((~src_px[x] & 0xf7de) >> 1); } src_px += src.stride; dst_px += dst.stride; } } img_t img_whiten_create(img_t src) { img_t dst = img_create(src.width, src.height); img_fill(dst, IMG_ALPHA); img_whiten(src, dst); return dst; } void img_darken(img_t src, img_t dst) { if(!img_target(dst, src.width, src.height)) return; img_pixel_t *src_px = src.pixels; img_pixel_t *dst_px = dst.pixels; for(int y = 0; y < src.height; y++) { for(int x = 0; x < src.width; x++) { if(src_px[x] == IMG_ALPHA) continue; dst_px[x] = (src_px[x] & 0xf7de) >> 1; } src_px += src.stride; dst_px += dst.stride; } } img_t img_darken_create(img_t src) { img_t dst = img_create(src.width, src.height); img_fill(dst, IMG_ALPHA); img_darken(src, dst); return dst; }