Image *image_sub(const Image *a, const Image *b, Image *out) { int wi, hi; for (hi = 0; hi < a->height; ++hi) for (wi = 0; wi < a->width; ++wi) color_sub(a->channels, sample(a,wi,hi), sample(b,wi,hi), sample(out,wi,hi)); return out; }
pixel_t truecolor_match_color(const rgba_t *color, rgba_t *error) { rgba_t approx; u32 r, g, b, a; r = COMPRESS_FROM_16BIT(color->r, red_len-1); g = COMPRESS_FROM_16BIT(color->g, green_len-1); b = COMPRESS_FROM_16BIT(color->b, blue_len-1); a = COMPRESS_FROM_16BIT(color->a, alpha_len-1); if (error) { approx.r = EXPAND_TO_16BIT(r, red_len-1); approx.g = EXPAND_TO_16BIT(g, green_len-1); approx.b = EXPAND_TO_16BIT(b, blue_len-1); approx.a = EXPAND_TO_16BIT(a, alpha_len-1); color_sub(error, color, &approx); } return rgba_pixel(r, g, b, a); }