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 #ifdef __HAVE_PF_ARGB3565__
00037
00038 #include "mmstools/mmstools.h"
00039
00040 #define MMSFB_BLIT_BLEND_ARGB_TO_ARGB3565(src, dst, dst_a, alpha) \
00041 SRC = src; \
00042 A = SRC >> 24; \
00043 if (A == 0xff) { \
00044 if (SRC==OLDSRC) { \
00045 dst = d; \
00046 alpha da; \
00047 } \
00048 else { \
00049 OLDSRC = SRC; \
00050 unsigned int r = (SRC << 8) >> 27; \
00051 unsigned int g = (SRC << 16) >> 26; \
00052 unsigned int b = (SRC & 0xff) >> 3; \
00053 d = (r << 11) \
00054 | (g << 5) \
00055 | b; \
00056 da = A >> 5; \
00057 dst = d; \
00058 alpha da; \
00059 } \
00060 } \
00061 else \
00062 if (!A) { \
00063 alpha dst_a; \
00064 } \
00065 else { \
00066 register unsigned short int DST = dst; \
00067 if ((DST==OLDDST)&&(dst_a==OLDDSTA)&&(SRC==OLDSRC)) { \
00068 dst = d; \
00069 alpha da; \
00070 } \
00071 else { \
00072 OLDDST = DST; \
00073 OLDDSTA = dst_a; \
00074 OLDSRC = SRC; \
00075 register unsigned int SA= 0x100 - A; \
00076 unsigned int a = dst_a; \
00077 unsigned int r = DST >> 11; \
00078 unsigned int g = (DST << 5) >> 10; \
00079 unsigned int b = DST & 0x1f; \
00080 a = (SA * a) >> 3; \
00081 r = (SA * r) >> 5; \
00082 g = (SA * g) >> 6; \
00083 b = (SA * b) >> 5; \
00084 a += A >> 5; \
00085 r += (SRC << 8) >> 27; \
00086 g += (SRC << 16) >> 26; \
00087 b += (SRC << 24) >> 27; \
00088 d = ((r >> 5) ? 0xf800 : (r << 11)) \
00089 | ((g >> 6) ? 0x07e0 : (g << 5)) \
00090 | ((b >> 5) ? 0x1f : b); \
00091 da = (a >> 8) ? 0x07 : a; \
00092 dst = d; \
00093 alpha da; \
00094 } \
00095 }
00096
00097
00098 void mmsfb_blit_blend_argb_to_argb3565(MMSFBSurfacePlanes *src_planes, int src_height, int sx, int sy, int sw, int sh,
00099 MMSFBSurfacePlanes *dst_planes, int dst_height, int dx, int dy) {
00100
00101 static bool firsttime = true;
00102 if (firsttime) {
00103 printf("DISKO: Using accelerated blend ARGB to ARGB3565.\n");
00104 firsttime = false;
00105 }
00106
00107
00108 unsigned int *src = (unsigned int *)src_planes->ptr;
00109 int src_pitch = src_planes->pitch;
00110
00111
00112 unsigned short int *dst = (unsigned short int *)dst_planes->ptr;
00113 int dst_pitch = dst_planes->pitch;
00114
00115
00116 unsigned char *dst_a;
00117 int dst_a_pitch;
00118 if (dst_planes->ptr2) {
00119
00120 dst_a = (unsigned char *)dst_planes->ptr2;
00121 dst_a_pitch = dst_planes->pitch2;
00122 }
00123 else {
00124
00125 dst_a = ((unsigned char *)dst_planes->ptr) + dst_planes->pitch * dst_height;
00126 dst_a_pitch = dst_planes->pitch / 4;
00127 }
00128
00129
00130 int src_pitch_pix = src_pitch >> 2;
00131 int dst_pitch_pix = dst_pitch >> 1;
00132 src+= sx + sy * src_pitch_pix;
00133 dst+= dx + dy * dst_pitch_pix;
00134 dst_a+= (dx >> 1) + dy * dst_a_pitch;
00135
00136
00137 if (dst_pitch_pix - dx < sw - sx)
00138 sw = dst_pitch_pix - dx - sx;
00139 if (dst_height - dy < sh - sy)
00140 sh = dst_height - dy - sy;
00141 if ((sw <= 0)||(sh <= 0))
00142 return;
00143
00144
00145 bool odd_left = (dx & 0x01);
00146 bool odd_right = ((dx + sw) & 0x01);
00147
00148
00149
00150
00151
00152
00153
00154 if (odd_left) {
00155
00156 dx++;
00157 sw--;
00158 src++;
00159 dst++;
00160 dst_a++;
00161 }
00162
00163 if (odd_right) {
00164
00165 sw--;
00166 }
00167
00168
00169
00170 unsigned short int OLDDST = (*dst) + 1;
00171 unsigned char OLDDSTA = (*dst_a) + 1;
00172 unsigned int OLDSRC = (*src) + 1;
00173 unsigned int *src_end = src + src_pitch_pix * sh;
00174 int src_pitch_diff = src_pitch_pix - sw;
00175 int dst_pitch_diff = dst_pitch_pix - sw;
00176 int dst_a_pitch_diff = dst_a_pitch - (sw >> 1);
00177 register unsigned short int d;
00178 register unsigned char da;
00179
00180
00181
00182 while (src < src_end) {
00183
00184 unsigned int *line_end = src + sw;
00185 while (src < line_end) {
00186 register unsigned int SRC;
00187 register unsigned int A;
00188 unsigned char alpha;
00189
00190
00191 MMSFB_BLIT_BLEND_ARGB_TO_ARGB3565(*src, *dst, ((*dst_a) >> 4), alpha=);
00192 MMSFB_BLIT_BLEND_ARGB_TO_ARGB3565(*(src+1), *(dst+1), ((*dst_a)&0x0f), alpha=(alpha<<4)|);
00193 dst+=2;
00194 src+=2;
00195
00196
00197 *dst_a = alpha;
00198 dst_a++;
00199 }
00200
00201
00202 src+= src_pitch_diff;
00203 dst+= dst_pitch_diff;
00204 dst_a+= dst_a_pitch_diff;
00205 }
00206 }
00207
00208 #endif
00209 #endif