//+----------------------------------------------------------------------------+ //| Description: Magic Set Editor - Program to make card games | //| Copyright: (C) Twan van Laarhoven and the other MSE developers | //| License: GNU General Public License 2 or later (see file COPYING) | //+----------------------------------------------------------------------------+ // ----------------------------------------------------------------------------- : Includes #include #include #include #include // ----------------------------------------------------------------------------- : Linear Blend // sqr(x) = x^2 template inline T sqr(T x) { return x * x; } void linear_blend(Image& img1, const Image& img2, double x1,double y1, double x2,double y2) { int width = img1.GetWidth(), height = img1.GetHeight(); if (img2.GetWidth() != width || img2.GetHeight() != height) { throw Error(_ERROR_3_("blending different sizes", "linear_blend", String()< fixed) mult = fixed; data1[0] = data1[0] + mult * (data2[0] - data1[0]) / fixed; data1[1] = data1[1] + mult * (data2[1] - data1[1]) / fixed; data1[2] = data1[2] + mult * (data2[2] - data1[2]) / fixed; data1 += 3; data2 += 3; } } // Blend Alpha for the two images. if (img1.HasAlpha() && img2.HasAlpha()) { Byte *alpha1 = img1.GetAlpha(), *alpha2 = img2.GetAlpha(); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { int mult = x * xm + y * ym + d; if (mult < 0) mult = 0; if (mult > fixed) mult = fixed; alpha1[0] = alpha1[0] + mult * (alpha2[0] - alpha1[0]) / fixed; alpha1 += 1; alpha2 += 1; } } } //transfer metadata img1.SetOption(wxIMAGE_OPTION_PNG_DESCRIPTION, metadata_merge(img1, img2)); } // ----------------------------------------------------------------------------- : Mask Blend void mask_blend(Image& img1, const Image& img2, const Image& mask) { int width = img1.GetWidth(), height = img1.GetHeight(); if (img2.GetWidth() != width || img2.GetHeight() != height) { throw Error(_ERROR_3_("blending different sizes", "masked_blend", String()< 1.0) { if (!img.HasAlpha()) return; else { Byte *im = img.GetAlpha(); for (size_t i = 0 ; i < size ; ++i) { im[i] = Byte(min(im[i] * alpha, 255.0)); } } } else { Byte b_alpha = Byte(alpha * 255); if (!img.HasAlpha()) { img.InitAlpha(); memset(img.GetAlpha(), b_alpha, size); } else { Byte *im = img.GetAlpha(); for (size_t i = 0 ; i < size ; ++i) { im[i] = (im[i] * b_alpha) / 255; } } } }