static ALLEGRO_COLOR reference_implementation( ALLEGRO_COLOR src_col, ALLEGRO_COLOR dst_col, ALLEGRO_COLOR blend_col, int src_format, int dst_format, int src_mode, int dst_mode, int src_alpha, int dst_alpha, int operation) { float sr, sg, sb, sa; float br, bg, bb, ba; float dr, dg, db, da; float r, g, b, a; float src, dst, asrc, adst; al_unmap_rgba_f(src_col, &sr, &sg, &sb, &sa); al_unmap_rgba_f(blend_col, &br, &bg, &bb, &ba); al_unmap_rgba_f(dst_col, &dr, &dg, &db, &da); /* Do we even have source alpha? */ if (operation == 0) { if (!has_alpha(src_format)) { sa = 1; } } r = sr * br; g = sg * bg; b = sb * bb; a = sa * ba; src = get_factor(src_mode, a); dst = get_factor(dst_mode, a); asrc = get_factor(src_alpha, a); adst = get_factor(dst_alpha, a); r = r * src + dr * dst; g = g * src + dg * dst; b = b * src + db * dst; a = a * asrc + da * adst; r = CLAMP(r); g = CLAMP(g); b = CLAMP(b); a = CLAMP(a); /* Do we even have destination alpha? */ if (!has_alpha(dst_format)) { a = 1; } return al_map_rgba_f(r, g, b, a); }
SDL_Surface* SDL_Resize(SDL_Surface *src, int new_w, int new_h, bool free, int filter) { SDL_Surface * dst; bool is_alpha = has_alpha(src); if (src->w == new_w && src->h == new_h) { //No change in size. return src; } Uint32 rmask = 0x000000ff, gmask = 0x0000ff00, bmask = 0x00ff0000, amask = 0xff000000; #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #endif dst = SDL_CreateRGBSurface(0, new_w, new_h, 32, rmask, gmask, bmask, amask); SDL_Surface * temp = SDL_ConvertSurface(src,dst->format,0); Resample(temp,dst,filter); SDL_FreeSurface(temp); temp = SDL_ConvertSurface(dst,src->format,0); SDL_FreeSurface(dst); if (is_alpha) { SDL_SetAlpha(temp, SDL_SRCALPHA, 0); } if (free) SDL_FreeSurface(src); return temp; }