QuadBlitter.cpp
Go to the documentation of this file.00001 //*** QuadBlitter.cpp *** 00002 00003 #include "QuadBlitter.h" 00004 #include "ColorHelper.h" 00005 #include "StandardLibrary.h" 00006 #include "Debug.h" 00007 00008 00009 QuadBlitter::EdgeBuffer QuadBlitter::edgeBuffer_; 00010 00011 /* // INTERPOLATION 00012 int offset=(u0>>16)+sourceHPitch*(v0>>16); 00013 unsigned short c1=sourceColor[offset]; 00014 unsigned short c2=sourceColor[offset+1]; 00015 unsigned short c3=sourceColor[offset+sourceHPitch]; 00016 unsigned short c4=sourceColor[offset+sourceHPitch+1]; 00017 unsigned char uf=(unsigned char)((u0&0xffff)>>8); 00018 unsigned char vf=(unsigned char)((v0&0xffff)>>8); 00019 unsigned short fc0=AlphaBlend16(c1,c2,uf); 00020 unsigned short fc1=AlphaBlend16(c3,c4,uf); 00021 unsigned short fcx=AlphaBlend16(fc0,fc1,vf); 00022 *pdata=fcx; 00023 */ 00024 00025 00026 // DstColor fylls med fillColor 00027 void QuadBlitter::Blit(unsigned short fillColor, unsigned short* targetColor, int targetHPitch, int targetVPitch, int targetX1, int targetY1, int targetX2, int targetY2, int targetX3, int targetY3, int targetX4, int targetY4) 00028 { 00029 // *** START EDGE SCANNING *** 00030 00031 // To avoid massive amounts of code duplication, the edge scanning code have been 00032 // written to cope with multiple scenarios, with features determined by #defines 00033 00034 #define EDGE_TYPE EdgeX 00035 00036 #include "QuadBlitter_scanning.inl" 00037 00038 #undef EDGE_TYPE 00039 00040 // *** END EDGE SCANNING *** 00041 00042 00043 // Draw rows 00044 unsigned short* data=targetColor+p0y*targetHPitch; 00045 EdgeX* edgePtr=edgeBuffer; 00046 for (int y=p0y; y<p3y; y++) 00047 { 00048 int xstart=(*edgePtr++).x; 00049 int width=(*edgePtr++).x-xstart; 00050 00051 unsigned short* pdata=data+xstart; 00052 for (int x=0; x<width; x++) 00053 { 00054 *pdata=fillColor; 00055 pdata++; 00056 } 00057 00058 // Advance to next rows 00059 data+=targetHPitch; 00060 } 00061 00062 } 00063 00064 // SrcColor kopieras till DstColor 00065 void QuadBlitter::Blit(unsigned short* sourceColor, int sourceHPitch, int sourceVPitch, unsigned short* targetColor, int targetHPitch, int targetVPitch, int sourceX1, int sourceY1, int sourceX2, int sourceY2, int sourceX3, int sourceY3, int sourceX4, int sourceY4, int targetX1, int targetY1, int targetX2, int targetY2, int targetX3, int targetY3, int targetX4, int targetY4) 00066 { 00067 sourceX2++; 00068 sourceX3++; 00069 sourceY3++; 00070 sourceY4++; 00071 00072 // *** START EDGE SCANNING *** 00073 00074 // To avoid massive amounts of code duplication, the edge scanning code have been 00075 // written to cope with multiple scenarios, with features determined by #defines 00076 00077 #define EDGE_TYPE EdgeXUV 00078 #define USE_UV 00079 00080 #include "QuadBlitter_scanning.inl" 00081 00082 #undef USE_UV 00083 #undef EDGE_TYPE 00084 00085 // *** END EDGE SCANNING *** 00086 00087 00088 // Draw rows 00089 unsigned short* data=targetColor+p0y*targetHPitch; 00090 EdgeXUV* edgePtr=static_cast<EdgeXUV*>(edgeBuffer_.buffer_); 00091 for (int y=p0y; y<p3y; y++) 00092 { 00093 int xstart=(*edgePtr).x; 00094 int u0=(*edgePtr).u; 00095 int v0=(*edgePtr).v; 00096 edgePtr++; 00097 00098 int xend=(*edgePtr).x; 00099 int u1=(*edgePtr).u; 00100 int v1=(*edgePtr).v; 00101 edgePtr++; 00102 00103 00104 int width=xend-xstart+1; 00105 00106 int stepU=(u1-u0)/width; 00107 int stepV=(v1-v0)/width; 00108 00109 unsigned short* pdata=data+xstart; 00110 for (int x=0; x<width; x++) 00111 { 00112 *pdata=sourceColor[(u0>>16)+sourceHPitch*(v0>>16)]; 00113 pdata++; 00114 u0+=stepU; 00115 v0+=stepV; 00116 } 00117 00118 // Advance to next rows 00119 data+=targetHPitch; 00120 } 00121 00122 } 00123 00124 // SrcColor blendas (SrcAlpha) med DstColor 00125 void QuadBlitter::Blit(unsigned short* sourceColor, unsigned char* sourceAlpha, int sourceHPitch, int sourceVPitch, unsigned short* targetColor, int targetHPitch, int targetVPitch, int sourceX1, int sourceY1, int sourceX2, int sourceY2, int sourceX3, int sourceY3, int sourceX4, int sourceY4, int targetX1, int targetY1, int targetX2, int targetY2, int targetX3, int targetY3, int targetX4, int targetY4) 00126 { 00127 sourceX2++; 00128 sourceX3++; 00129 sourceY3++; 00130 sourceY4++; 00131 00132 // *** START EDGE SCANNING *** 00133 00134 // To avoid massive amounts of code duplication, the edge scanning code have been 00135 // written to cope with multiple scenarios, with features determined by #defines 00136 00137 #define EDGE_TYPE EdgeXUV 00138 #define USE_UV 00139 00140 #include "QuadBlitter_scanning.inl" 00141 00142 #undef USE_UV 00143 #undef EDGE_TYPE 00144 00145 // *** END EDGE SCANNING *** 00146 00147 00148 // Draw rows 00149 unsigned short* data=targetColor+p0y*targetHPitch; 00150 EdgeXUV* edgePtr=static_cast<EdgeXUV*>(edgeBuffer_.buffer_); 00151 for (int y=p0y; y<p3y; y++) 00152 { 00153 int xstart=(*edgePtr).x; 00154 int u0=(*edgePtr).u; 00155 int v0=(*edgePtr).v; 00156 edgePtr++; 00157 00158 int xend=(*edgePtr).x; 00159 int u1=(*edgePtr).u; 00160 int v1=(*edgePtr).v; 00161 edgePtr++; 00162 00163 00164 int width=xend-xstart+1; 00165 00166 int stepU=(u1-u0)/width; 00167 int stepV=(v1-v0)/width; 00168 00169 unsigned short* pdata=data+xstart; 00170 for (int x=0; x<width; x++) 00171 { 00172 int offset=(u0>>16)+sourceHPitch*(v0>>16); 00173 unsigned char srcalpha=sourceAlpha[offset]; 00174 if (srcalpha>0) 00175 { 00176 *pdata=AlphaBlend16(*pdata,sourceColor[offset],srcalpha); 00177 } 00178 00179 pdata++; 00180 u0+=stepU; 00181 v0+=stepV; 00182 } 00183 00184 // Advance to next rows 00185 data+=targetHPitch; 00186 } 00187 00188 } 00189 00190 00191 // SrcColor blendas (SrcAlpha*BlitAlpha) med DstColor 00192 void QuadBlitter::Blit(unsigned char alpha, unsigned short* sourceColor, unsigned char* sourceAlpha, int sourceHPitch, int sourceVPitch, unsigned short* targetColor, int targetHPitch, int targetVPitch, int sourceX1, int sourceY1, int sourceX2, int sourceY2, int sourceX3, int sourceY3, int sourceX4, int sourceY4, int targetX1, int targetY1, int targetX2, int targetY2, int targetX3, int targetY3, int targetX4, int targetY4) 00193 { 00194 sourceX2++; 00195 sourceX3++; 00196 sourceY3++; 00197 sourceY4++; 00198 00199 // *** START EDGE SCANNING *** 00200 00201 // To avoid massive amounts of code duplication, the edge scanning code have been 00202 // written to cope with multiple scenarios, with features determined by #defines 00203 00204 #define EDGE_TYPE EdgeXUV 00205 #define USE_UV 00206 00207 #include "QuadBlitter_scanning.inl" 00208 00209 #undef USE_UV 00210 #undef EDGE_TYPE 00211 00212 // *** END EDGE SCANNING *** 00213 00214 00215 // Draw rows 00216 unsigned short* data=targetColor+p0y*targetHPitch; 00217 EdgeXUV* edgePtr=static_cast<EdgeXUV*>(edgeBuffer_.buffer_); 00218 for (int y=p0y; y<p3y; y++) 00219 { 00220 int xstart=(*edgePtr).x; 00221 int u0=(*edgePtr).u; 00222 int v0=(*edgePtr).v; 00223 edgePtr++; 00224 00225 int xend=(*edgePtr).x; 00226 int u1=(*edgePtr).u; 00227 int v1=(*edgePtr).v; 00228 edgePtr++; 00229 00230 00231 int width=xend-xstart+1; 00232 00233 int stepU=(u1-u0)/width; 00234 int stepV=(v1-v0)/width; 00235 00236 unsigned short* pdata=data+xstart; 00237 for (int x=0; x<width; x++) 00238 { 00239 int offset=(u0>>16)+sourceHPitch*(v0>>16); 00240 unsigned char srcalpha=sourceAlpha[offset]; 00241 if (srcalpha>0) 00242 { 00243 unsigned char outalpha=(srcalpha*alpha)>>8; 00244 *pdata=AlphaBlend16(*pdata,sourceColor[offset],outalpha); 00245 } 00246 00247 pdata++; 00248 u0+=stepU; 00249 v0+=stepV; 00250 } 00251 00252 // Advance to next rows 00253 data+=targetHPitch; 00254 } 00255 00256 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
