00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mmsgui/fb/mmsfbconv.h"
00034
00035 #ifdef __HAVE_PF_ARGB__
00036
00037 #include "mmstools/mmstools.h"
00038
00039 void mmsfb_blit_blend_coloralpha_argb_to_argb(MMSFBSurfacePlanes *src_planes, int src_height, int sx, int sy, int sw, int sh,
00040 MMSFBSurfacePlanes *dst_planes, int dst_height, int dx, int dy,
00041 unsigned char alpha) {
00042
00043 if (alpha == 0xff) {
00044
00045 mmsfb_blit_blend_argb_to_argb(src_planes, src_height, sx, sy, sw, sh,
00046 dst_planes, dst_height, dx, dy);
00047 return;
00048 }
00049
00050
00051 static bool firsttime = true;
00052 if (firsttime) {
00053 printf("DISKO: Using accelerated blend coloralpha ARGB to ARGB.\n");
00054 firsttime = false;
00055 }
00056
00057
00058 if (!alpha)
00059
00060 return;
00061
00062
00063 unsigned int *src = (unsigned int *)src_planes->ptr;
00064 int src_pitch = src_planes->pitch;
00065
00066
00067 unsigned int *dst = (unsigned int *)dst_planes->ptr;
00068 int dst_pitch = dst_planes->pitch;
00069
00070
00071 int src_pitch_pix = src_pitch >> 2;
00072 int dst_pitch_pix = dst_pitch >> 2;
00073 src+= sx + sy * src_pitch_pix;
00074 dst+= dx + dy * dst_pitch_pix;
00075
00076
00077 if (dst_pitch_pix - dx < sw - sx)
00078 sw = dst_pitch_pix - dx - sx;
00079 if (dst_height - dy < sh - sy)
00080 sh = dst_height - dy - sy;
00081 if ((sw <= 0)||(sh <= 0))
00082 return;
00083
00084 unsigned int OLDDST = (*dst) + 1;
00085 unsigned int OLDSRC = (*src) + 1;
00086 unsigned int *src_end = src + src_pitch_pix * sh;
00087 int src_pitch_diff = src_pitch_pix - sw;
00088 int dst_pitch_diff = dst_pitch_pix - sw;
00089 register unsigned int d;
00090
00091 register unsigned int ALPHA = alpha;
00092 ALPHA++;
00093
00094
00095 while (src < src_end) {
00096
00097 unsigned int *line_end = src + sw;
00098 while (src < line_end) {
00099
00100 register unsigned int SRC = *src;
00101
00102
00103 register unsigned int A = SRC >> 24;
00104 if (A) {
00105
00106 register unsigned int DST = *dst;
00107
00108 if ((DST==OLDDST)&&(SRC==OLDSRC)) {
00109
00110 *dst = d;
00111 dst++;
00112 src++;
00113 continue;
00114 }
00115 OLDDST = DST;
00116 OLDSRC = SRC;
00117
00118
00119 A = (ALPHA * A) >> 8;
00120 unsigned int sr = (ALPHA * (SRC & 0xff0000)) >> 24;
00121 unsigned int sg = (ALPHA * (SRC & 0xff00)) >> 16;
00122 unsigned int sb = (ALPHA * (SRC & 0xff)) >> 8;
00123 register unsigned int SA= 0x100 - A;
00124
00125 unsigned int a = DST >> 24;
00126 unsigned int r = (DST << 8) >> 24;
00127 unsigned int g = (DST << 16) >> 24;
00128 unsigned int b = DST & 0xff;
00129
00130
00131 a = (SA * a) >> 8;
00132 r = (SA * r) >> 8;
00133 g = (SA * g) >> 8;
00134 b = (SA * b) >> 8;
00135
00136
00137 a += A;
00138 r += sr;
00139 g += sg;
00140 b += sb;
00141 d = ((a >> 8) ? 0xff000000 : (a << 24))
00142 | ((r >> 8) ? 0xff0000 : (r << 16))
00143 | ((g >> 8) ? 0xff00 : (g << 8))
00144 | ((b >> 8) ? 0xff : b);
00145 *dst = d;
00146 }
00147
00148 dst++;
00149 src++;
00150 }
00151
00152
00153 src+= src_pitch_diff;
00154 dst+= dst_pitch_diff;
00155 }
00156 }
00157
00158 #endif